1)文件上传
示例:
import requests
files={'file':open(favicon.ico','rb')}
r=requests.post("http://httpbin.org/post",filles=files)
print(r.text)
注意:favicon.ico需要和当前脚本在同一目录下
2)Cookies
获取cookies:
import requests
r=requests.get('https://www.baidu.com')
print(r.cookies)
for key,value in r.cookies.items():
print(key + '=' +value)
使用cookies来维持登陆状态:
import requests
headers={
'Cookie':'BAIDUID=032232C5AFD4FC60EA7ADC5EE0D18E5F:FG=1; BIDUPSID=032232C5AFD4FC60EA7ADC5EE0D18E5F; PSTM=1520942560; BDUSS=X55ZzE3SEtpSTZHbU9lQTRiOXczZHRFcThJVC1JbTBzZTQ2VWRnUkhDdzlXZlphQVFBQUFBJCQAAAAAAAAAAAEAAABDZC0jvbW3-b~JtO~LvL~PtqgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD3Mzlo9zM5aV; BD_UPN=12314753; delPer=0; BD_CK_SAM=1; PSIN