1.给requests请求添加cookie
headers ={
'cookie':'__utmz=149472179.1639958238.3.2.utmcsr=jingjiniao.info|utmccn=(referral)|utmcmd=referral|utmcct=/; phpbb3_kh9pm_u=14660; phpbb3_kh9pm_k=964b81a38ca97ac6; phpbb3_kh9pm_sid=5f8f0ed0ba402d1d38904c5792d14302; __utma=149472179.1447947063.1639283592.1642730394.1642820074.17; __utmc=149472179; __utmt=1; __utmb=149472179.3.10.1642820074'
}
resp = requests.get(url,headers=headers)
还可以添加一些其它参数
import requests
1.url
网址
2.headers
请求头
3.cookies
cookie值
4.params
参数
5.data
请求体
6.json
请求体
7.代理proxies
proxies_dict ={
}
res =requests.get('xxxxxxxxxxxxx',proxies = proxies_dict)
8.认证
from requests.auth import HTTPProxyAuth
proxies_dict ={
}
auth = HTTPProxyAuth('用户名','密码')
res = requests.get('url',data={},proxies=proxiesDict,auth=auth)
9.上传文件files
file_dict = {
'f1':open('xxxx.txt','rb')
}
requests.requests(
method='POST',
url='',
files=file_dict
)
10.弹窗认证 用户名密码,加密,放在请求头里串给后台
from requests.auth import HTTPBasicAuth,HTTPDigestAuth
res = requests.get('url',auth=HTTPBasicAuth('用户名','密码'))
print(res.text)
11.超神 timeout
res = requests.get('url',timeou(1)链接时间,timeout(5,1)链接和返回时间)
12.允许重定向 allow_redirects
res = resquests.get('url',allow_redirects =False/True)
不会重定向,会重定向
13.大文件下载 stream
from contextlib import closing
with closing(requests.get('url',stream=True)) as r1;
for i in r1.iter_content();
print(i)
14.证书 cert
requests.get('url',cert='xxxxxxxx.pem')
requests.get('url',cert='xxxxxxxx.pem','xxxxxxxxxxxxxxxxx.key')
15.确认verify=False