requests 库的(stream)
来源:互联网 发布:房地产软件有哪些 明源 编辑:程序博客网 时间:2024/05/22 15:31
查找requests的相应资料
By default, when you make a request, the body of the response is
downloaded immediately. You can override this behaviour and defer
downloading the response body until you access the Response.content
attribute with the stream parameter:
- 1
- 2
At this point only the response headers have been downloaded and the
connection remains open, hence allowing us to make content retrieval
conditional:
- 1
- 2
- 3
只有headers头被下载了,body中的数据还没有被下载,这样就能避免不必要的流量开销,只有当你使用r.content 的时候,所有body内容才会被下载
You can further control the workflow by use of the
Response.iter_content() and Response.iter_lines() methods.
Alternatively, you can read the undecoded body from the underlying
urllib3 urllib3.HTTPResponse at Response.raw.
实时上还可以使用Response.iter_content() Response.iter_lines()
Response.raw()来自己决定要读取多少数据
最后要注意的是,使用stream=True以后需要自己执行Response的
关闭操作close
默认情况下requests对URL的访问是阻塞式的,可以通过使用
1)grequests
2)requests-futures
来实现非阻塞式的访问
参考资料
1.http://docs.python-requests.org/en/master/user/advanced/#body-content-workflow
2.http://docs.python-requests.org/en/master/user/advanced/#blocking-or-non-blocking
3.http://docs.python-requests.org/en/master/user/advanced/#blocking-or-non-blocking
- requests 库的(stream)
- requests 库的另类用法(stream)
- Requests库的用法
- requests库的安装
- python的requests库
- Requests库的入门
- requests 库的安装
- Requests库的使用
- Requests库的使用
- (三)Requests库
- python的requests类库(一)requests库和urllib包对比:一个简单get请求
- requests库的简单函数
- python Requests库的用法
- python的 requests库使用
- requests库的基础使用
- requests库,爬虫的第一步
- python的requests库详解
- Python 第三方库(requests)的使用(转)
- bzoj1485: [HNOI2009]有趣的数列
- fmpdam1.2协议报文格式说明
- 刷单、套证不止,美团是要成新《反不正当竞争法》“第一案”?
- 用黑金例子说如何快速分配引脚
- CentOS 6.2 下samba 服务的配置
- requests 库的(stream)
- python3 安装 Beautifulsoup4结果发现版本不兼容的问题解决
- 总结-2017/12/15
- Gym 101617D 线段树
- Gym 101617D dp
- PHP 程序员解决问题能力的八个级别
- hbase常见错误---IDE连接操作hbase报错 Insufficient permissions (user=Administrator
- 比特币或区块链的创业思路【起始篇】
- Containers cannot resolve DNS if docker host uses 127.0.0.1 as resolver