requests发送请求后会返回响应对象
import requests
respone = requests.get('xxx')
respone属性
响应体--字符串形式
print(respone.text)
响应体--bytes格式
print(respone.content)
响应状态码
print(respone.status_code)
响应头
print(respone.headers)
响应的cookie
print(respone.cookies)
cookiejar对象--转成字典格式
print(respone.cookies.get_dict())
cookie的value值
print(respone.cookies.items())
请求地址
print(respone.url)
访问历史---需要重定向才会有
print(respone.history)
编码格式
print(respone.encoding)
图片,视频---》迭代着把数据保存到本地
response.iter_content()
header={
'Referer':'https://www.tupianzj.com/'
}
res=requests.get('https://img.lianzhixiu.com/uploads/allimg/180514/9-1P514153131.jpg',headers=header)
with open('code.jpg','wb') as f:
for line in res.iter_content(chunk_size=1024):
f.write(line)