简单例子
# 发送 get 请求
url = 'https://www.baidu.com'
res = requests.get(url)
print(res.text)
安装
pipe install...读取全部内容
r.raw.read()
响应状态码
r = requests.get('http://httpbin.org/get')
# 获取状态码
print(r.status_code)
# 捕获请求错误..., 例如: 404,500 等
r = post('https://www.baidu.com/api')
try:
# 如果请求错误,将抛出异常
r.raise_for_status()
except...', 'payment'),
403: ('forbidden',),
404: ('not_found', '-o-'),
405: ('method_not_allowed'...历史记录
Requests 将自动处理重定向, history 收集了重定向的请求体
r = get(url,cookies=cookies)
print(r.history)
# []
# 无重定向时,