爬虫之 requests小结

文档
English – http://www.python-requests.org/en/master/
中文 – http://cn.python-requests.org/zh_CN/latest/
快速上手– http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
高级用法 – http://cn.python-requests.org/zh_CN/latest/user/advanced.html
源码
http://cn.python-requests.org/zh_CN/latest/user/install.html#id2

Requests 支持 Python 2.6—3.5,而且能在PyPy下完美运行。

import requests

r = requests.get(url) # r 是response的对象
r = requests.post(url, data = post_data)  # 提交表单 字典类型的表单数据
r = requests.get(url, headers=headers)  # headers 字典类型的请求头
r = requests.get(url, cookies=cookies)  # 带cookies的请求
r = requests.get("http://example.org", proxies=proxies) # 通过代理请求
proxies = {
  "http": "http://10.10.1.10:3128",
  "https": "http://10.10.1.10:1080",
}



r.text # 得到页面文本的内容 Unicode型的数据
r.encoding # 网页的编码 可以设置如 r.encoding = 'utf-8'
r.content # bytes型也就是二进制的数据, 想取图片,文件,则可以通过r.content
r.status_code  # 状态码
r.headers  # 服务器返回的响应头
r.cookies  # cookies
r.request.headers  # 发送到服务器的请求头

requests.get('http://github.com', timeout=0.001)  # timeout 设置超时时间
r.json() # 内置json解码器


s = requests.Session()  # 保持cookie  如保持登陆状态

具体用法 看文档
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值