requests常见的几种解码方式

在得到返回的对象(response)后,一般不去刻意查看,是不知道编码方式的。

通常直接猜即可,因为大多数都是使用的“utf-8”。

在requests里的快捷的解码方式可以使用如下几种:

 

1.

response.text

·类型:str

·解码类型:根据http头部对响应的编码作出推测

·修改:response.encoding="utf-8"

2.

response.content.encode()

这里encode默认使用“utf-8”

·类型:bytes

·解码方式:没指定

3.

response.content.encode("gbk')

2020-07-24

原文地址:https://www.cnblogs.com/cheflone/p/13374202.html