0
点赞
收藏
分享

微信扫一扫

httpx 返回中文乱码解决方案

Ewall_熊猫 2022-01-05 阅读 73
python
import httpx

link = '要请求的网页链接'
r = httpx.get(link)

这里 r.text 返回的内容是中文乱码, 怎么办?

首先查看返回的html页面 header Content-Type 的值是什么

<meta http-equiv="Content-Type" content="text/html; charset=big5">

然后

r.encoding = 'big5'
print(r.text)

这样就可以动态修改返回内容的编码了

举报

相关推荐

0 条评论