码迷,mamicode.com
首页 > 编程语言 > 详细

Python requests

时间:2016-05-06 23:31:35      阅读:490      评论:0      收藏:0      [点我收藏+]

标签:

Python requests备忘

0x01

1 #coding:utf-8
2 import requests
3 
4 res = requests.get(http://www.baidu.com)
5 print res.status_code
6 print res.headers[content-type]  #头部信息
7 print res.encoding                 #编码信息
8 print res.text
9 print res.content

0x02

payload

1 import requests
2 
3 payload = {username:admin,password:adminhehe_a}
4 res = requests.get(http://x/index.php,params=payload)
5 print res.url
6 
7 http://x/index.php?username=admin&password=adminhehe_a

0x03

1 r = requests.get(http://ip.taobao.com/service/getIpInfo.php?ip=122.88.60.28)
2 print r.json()[data][country]

0x04

超时时间

1 requests.get(http://github.com, timeout=0.001)

0x05

代理访问

1 import requests
2  
3 proxies = {
4   "http": "http://10.10.1.10:3128",
5   "https": "http://10.10.1.10:1080",
6 }
7  
8 requests.get("http://www.xxx.com", proxies=proxies)

需要账户和密码时

1 proxies = {
2     "http": "http://user:pass@10.10.1.10:3128/",
3 }

0x06

自定义请求头

1 headers = {User-Agent: alexkh}
2 r = requests.get(http://www.xxx.com, headers = headers)

0x07

获取网页返回吗

1 def get_status(url):
2     r = requests.get(url, allow_redirects = False)
3     return r.status_code
4  
5 print get_status(http://www.zhidaow.com)

原文:http://www.sharejs.com/codes/python/9013

Python requests

标签:

原文地址:http://www.cnblogs.com/trojan-z/p/5467378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!