好好研究requests库

这库的文档必须得好好看啊。下面展示一些 内联代码片

// 二进制相应内容,对于非文本得请求以字节得方式访问请求响应体
// An highlighted block
res = requests.get(url)
res_byte = res.content

下面展示一些 内联代码片

// 例如以请求返回的二进制数据创建一张图片
// An highlighted block
from PIL import Image
from io import BytesIO
i = Image.open(BytesIO(r.content))

下面展示一些 内联代码片

// A code block
var foo = 'bar';
with open(filename,'wb') as fd:
	for chunk in r,iter_content(chunk_size):
		fd.write(chunk)

Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place.
chunk_size must be of type int or None. A value of None will function differently depending on the value of stream. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk.
If decode_unicode is True, content will be decoded using the best available encoding based on the response.
百度翻译:
迭代响应数据。当对请求设置stream=True时,这避免了将内容一次读入内存以获得大响应。块大小是它应该读入内存的字节数。这不一定是解码时返回的每个项目的长度。

块大小必须是int类型或None类型。值None将根据流的值发挥不同的作用。stream=True将在数据到达时读取接收到的数据块的大小。如果stream=False,数据将作为单个块返回。

如果decode\u unicode为True,则将根据响应使用最佳可用编码对内容进行解码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值