Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0521
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在:
- 个人网站: `https://oeasy.org`
- 蓝桥云课: `https://www.lanqiao.cn/courses/3584`
- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
- Gitee: `https://gitee.com/overmind1980/oeasypython`
---
| 状态码 |
状态 |
| 200 |
Ok |
| 304 |
Not modified |
| 404 |
Not found |
| 中文 |
英文 |
发送方 |
接收方 |
| 请求 |
request |
浏览器 |
服务器 |
| 响应 |
response |
服务器 |
浏览器 |

- 浏览的过程 是
- 在客户机上浏览器
- 服务器接收 请求
- 浏览器收到 response 并渲染成页面

-
爬虫就假装 自己是一个浏览器
-
那我应该 如何 假装自己是个浏览器 呢?

import requests
requests
help(requests)



import requests
requests.get("http://localhost/")


sudo service nginx start
sudo service nginx status

import requests
requests.get("http://localhost/")

import requests
r = requests.get("http://localhost/")

- Response 对象
- 包括了一个 http 请求的返回结果
- requests.models.Response

- r 里面有很多属性
- content 就是 可以读出来的内容
- 形式是 字节序列 bytes

r.content
type(r.content)




| 属性 |
类型 |
| content |
字节序列 |
| text |
字符串序列 |

s = r.content.decode()
print(s)

b = r.text.encode()
print(b)

print(b_html.decode()==s_html)
print(s_html.encode()==b_html)

- 编码和解码
- 可以查到requests这个包的 帮助 吗?





- 这样 我们就可以
- 假装自己是一个浏览器
- 完成了 http get 的过程
| 属性 |
类型 |
| content |
字节序列 |
| text |
字符串序列 |
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。