requests.requests(method,url,**kwargs)
**kwargs:控制访问的参数
params:字典或字节序列,作为参数增加到url中
例:
>>>kv = {'key1: value1','key2: value2'}
>>>r = requests.requests('GET','https://www.baidu.com',params = kv)
>>>print(r.url)
https://www.baidu.com/?key1 = value1&key2 = value2
data:字典、字节序列或文件对象,作为Request的内容
例:
>>>kv = {'key1: value1','key2: value2'}
>>>r = requests.requests('POST','https://www.baidu.com',data = kv)
>>>body = '主体内容'
>>>r = requests.requests('POST','https://www.baidu.com',data = body)
json:JSON格式的数据,作为Resquests的内容
例:
>>>kv = {'key1: value1','key2: value2'}
>>>r = requests.requests('POST','https://www.baidu.com',data = kv)
headers:字典,HTTP定制头
例:
>>>hd = {'user-agent': 'Chrome/10'} #火狐浏览器的第十个版本
>>>r = requests.requests('POST','https://www.baidu.com',headers = hd)
cookies:自典或CookieJar,Resquest中的cookie
auth:元组,支持HTTP认证功能
files:自典类型,传输文件
例:
>>>fs = {'file': open('data.xls', 'rb')}
>>>r = requests.requests('POST','https://baidu.com',files = fs)
timeout:设置超时时间,秒为单位
例:
>>>r = request.requests('GET','https://baidu.com',timeout = 10)
proxies:自典类型,设定代理访问服务器,可以增加登录认证
例:
>>>pxs = {‘http’: 'http://user:pass@10.10.10.1:1234'
'https’: 'http://10.10.10.1:4321' }
>>>r = request.requests('GET','https://baidu.com',proxies = pxs)
allow_redirects:True/False,默认为True,重定向开关
stream:True/False,默认为True,获取内容立即下载开关
verify:True/False,默认为True,认证SSL证书开关
cert:本地SSL证书路径