解决Python库Requests中文乱码

当使用Python库requests进行网络请求的时候:

r = requests.get(url)
1

使用

r.text返回的是Unicode型的数据。

r.content返回的是bytes型的数据。

如果你想取文本,使用r.text。
如果想取图片,文件,则可以通过r.content。

2

Requests库的自身编码为: r.encoding = ‘ISO-8859-1’
修改编码:

r.encoding='utf-8'
r.text
发布了140 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/LU_ZHAO/article/details/104859403
今日推荐