r = requests.get('https://api.github.com/events', params = {'key1': 'value1', 'key2': 'value2'})
r = requests.get('https://api.github.com/some/endpoint', headers={'user-agent': 'my-app/0.0.1'})
r = requests.get('http://httpbin.org/cookies', cookies=dict(cookies_are='working'))
r = requests.get('http://github.com', allow_redirects=False) #禁用重定向
r = requests.get('http://github.com', timeout=0.001) # 设置请求超时时间
r = requests.get(url, cookies=requests.cookies.RequestsCookieJar().set('tasty_cookie', 'yum',
domain='httpbin.org',
path='/cookies'))
r = requests.post('http://httpbin.org/post', data = {'key':'value'})
r = requests.post('http://httpbin.org/post', data=(('key1', 'value1'), ('key1', 'value2'))) #多个元素同一个key
r = requests.post('https://api.github.com/some/endpoint', data=json.dumps({'some': 'data'}))
r = requests.post('https://api.github.com/some/endpoint', json={'some': 'data'})
r = requests.post('http://httpbin.org/post', files={'file': open('report.xls', 'rb')}) # 上传文件
r = requests.post(url, files={'file': ('report.xls',
open('report.xls', 'rb'),
'application/vnd.ms-excel',
{'Expires': ''})}) # 显式地设置文件名,文件类型和请求头
r = requests.put('http://httpbin.org/put', data = {'key':'value'})
r = requests.delete('http://httpbin.org/delete')
r = requests.head('http://httpbin.org/get')
r = requests.options('http://httpbin.org/get') r.status_code: 返回的状态码
r.url: 打印输出拼接后的URL
r.text:响应的body内容
r.encoding: 改变响应body的编码方式
r.content: 二进制的响应body。content会自动解码 gzip 和deflate压缩
r.headers: 以字典对象存储服务器响应头,但是这个字典比较特殊,字典键不区分大小写,若键不存在则返回None
r.json(): 响应的json内容
r.raw(): 原始套接字响应
r.cookies['example_cookie_name']: 访问响应中的cookies
r.history: requests默认自动重定向,可以看重定向的记录

requests高级用法:http://docs.python-requests.org/zh_CN/latest/user/advanced.html#advanced

requests的基本用法的更多相关文章

  1. (转)Python爬虫利器一之Requests库的用法

    官方文档 以下内容大多来自于官方文档,本文进行了一些修改和总结.要了解更多可以参考 官方文档 安装 利用 pip 安装 $ pip install requests 或者利用 easy_install ...

  2. Python爬虫利器一之Requests库的用法

    前言 之前我们用了 urllib 库,这个作为入门的工具还是不错的,对了解一些爬虫的基本理念,掌握爬虫爬取的流程有所帮助.入门之后,我们就需要学习一些更加高级的内容和工具来方便我们的爬取.那么这一节来 ...

  3. 芝麻HTTP: Python爬虫利器之Requests库的用法

    前言 之前我们用了 urllib 库,这个作为入门的工具还是不错的,对了解一些爬虫的基本理念,掌握爬虫爬取的流程有所帮助.入门之后,我们就需要学习一些更加高级的内容和工具来方便我们的爬取.那么这一节来 ...

  4. Python之Requests的高级用法

    # 高级用法 本篇文档涵盖了Requests的一些更加高级的特性. ## 会话对象 会话对象让你能够跨请求保持某些参数.它也会在同一个Session实例发出的所有请求之间保持cookies. 会话对象 ...

  5. python爬虫---requests库的用法

    requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 因为是第三方库,所以使用前需要cmd安装 pip install requests 安装完成后import一下 ...

  6. 爬虫 requests模块高级用法

    一 介绍 #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) #注意:requests库发送请求将网页内 ...

  7. python的扩展包requests的高级用法

    Python 标准库中的 urllib2 模块提供了你所需要的大多数 HTTP 功能,但是它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工作,甚至包括各种方法覆盖,来完成最 ...

  8. requests 的基本用法

    r = requests.get('www.baidu.com') r.request.headers{'User-Agent': 'python-requests/2.18.4', 'Accept- ...

  9. 9.Python爬虫利器一之Requests库的用法(一)

    requests 官方文档: http://cn.python-requests.org/zh_CN/latest/user/quickstart.html request 是一个第三方的HTTP库 ...

随机推荐

  1. Django知识点

    一.Django        pip3 install django            C:\Python35\Scripts        # 创建Django工程    django-adm ...

  2. Elasticsearch之删除索引

    1. #删除指定索引    # curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-2018.08.09    {&qu ...

  3. asp.net core 系列 4 注入服务的生存期

    一.服务的生存期 在容器中每个注册的服务,根据程序应用需求都可以选择合适的服务生存期,ASP.NET Core 服务有三种生存期配置: (1) Transient:暂时生存期,在每次请求时被创建. 这 ...

  4. Error: Default interface methods are only supported starting with Android N (--min-api 24): java.io.InputStream org.apache.poi.sl.usermodel.ObjectShape.readObjectData()

    项目运行的时候,如果报错 Error: Default interface methods are only supported starting with Android N (--min-api ...

  5. Unity实现c#热更新方案探究(二)

    转载请标明出处:http://www.cnblogs.com/zblade/ 一.IOS对DLL热更新的禁止 紧接上文,继续对C#热更新的研究.上文中,已经说了如何基于appDomain来实现对DLL ...

  6. SpringBoot完美配置阿里云的文件上传

    新建一个config类 AliyunOSS.java @Configuration @Data public class AliyunOSS { private OSSClient ossClient ...

  7. 我对C#的认知。

    关于开发者的技术水平到底该如何定义,到底一个人的技术水平应该定位在高.中.低的标准是什么呢?很多人觉得这是一个仁者见仁的问题,有人觉得根据公司的那个员工等级判断.答案是肯定不是,从纯开发技术的角度来分 ...

  8. 第一册:lesson 103.

    原文:The French text. How was the exam, Richard? Not too bad. I think I passed in English and Mathemat ...

  9. Java学习笔记之——IO

    一. IO IO读写 流分类: 按照方向:输入流(读),输出流(写) 按照数据单位:字节流(传输时以字节为单位),字符流(传输时以字符为单位) 按照功能:节点流,过滤流 四个抽象类: InputStr ...

  10. Vue的使用

    mvc model view controller mvvm m=>model v=>view 双向数据绑定 数据在视图呈现:在表单里用v-model,在表单外用{{}},也可以用v-te ...