介绍
python的requests模块是python一个强大的第三方HTTP请求库,简单易用
安装: pip install requests
import requests
url=‘http://new.nginxs.net/ip.php‘
s=requests.get(url) s=requests.post(url) s=requests.delete(url) s=requests.options(url)
net_para = {‘localdns‘:‘8.8.8.8‘,‘ip‘:‘192.168.1.2‘} #这里是一个字典 requests.post(url,data=net_para)
header={"User-Agent":"Mozilla/5.0(X11;Ubuntu;Linuxx86_64;rv:39.0)Gecko/20100101Firefox/39.0"} #这里也是一个字典 s=requests.get(url,headers=headers)
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
本文出自 “nginxs小白” 博客,转载请与作者联系!
原文:http://nginxs.blog.51cto.com/4676810/1893262