运维python拓展(一)requests使用
2017-01-19 21:13
190 查看
介绍python的requests模块是python一个强大的第三方HTTP请求库,简单易用安装: pip install requests
import requestsurl='http://new.nginxs.net/ip.php'
import requestsurl='http://new.nginxs.net/ip.php'
requet使用http各种方法
s=requests.get(url) s=requests.post(url) s=requests.delete(url) s=requests.options(url)
requests模块请求传参
net_para = {'localdns':'8.8.8.8','ip':'192.168.1.2'} #这里是一个字典 requests.post(url,data=net_para)
定制header信息
header={"User-Agent":"Mozilla/5.0(X11;Ubuntu;Linuxx86_64;rv:39.0)Gecko/20100101Firefox/39.0"} #这里也是一个字典 s=requests.get(url,headers=headers)
添加cookies
cookies={'from-my': 'browser'} requests.get(url,cookies=cook)
添加超时时间
s = requests.get(url, timeout=0.001 )
添加代理
proxies={"http":"http://109.226.237.185:80"} #这里同样是字典,可以写多个类型代理例如https,socket4,socket5等等 proxies = { "http": "http://user:pass@10.10.1.10:3128/", "https": "http://10.10.1.10:1080", } s=requests.get(url,proxies=proxies)
用户验证
response = requests.get(url,auth=('dan','h0tdish'))
请求结果信息获取
print s.content #请求返回文本同text print s.headers #http头信息 print s.apparent_encoding #属性编码 print s.cookies #获取cookies print s.elapsed #相应时间 >>> print s.is_permanent_redirect #是否永久跳转 False
相关文章推荐
- 运维python拓展(一) urllib2使用
- python-requests 必需如下使用才能保持keep-alive
- python中的requests使用
- Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册
- python3控制路由器--使用requests重启极路由.py
- Python3控制路由器――使用requests重启极路由.py
- windows下安装requests模块 到python,eclipse可以使用
- Python3使用requests发闪存的方法
- 使用Python Requests上传表单数据和文件
- python 使用requests第三方库自动登陆新浪微博
- Python3控制路由器――使用requests重启极路由.py
- python requests使用
- Python爬虫(使用requests)
- python的requests初步使用
- Python――深入理解urllib、urllib2及requests(requests不建议使用?)
- python的requests初步使用
- 使用Protocol Buffers的C语言拓展提速Python程序的示例
- 在使用python requests 库时,通过post上传名称为中文文件时我遇到的问题
- python的requests初步使用
- Python3使用requests登录人人影视网站的方法