Python 中文乱码问题

2020-06-15  本文已影响0人  马卡他弟本来是我的昵称

问题

requests 返回的数据中,中文出现乱码

image
decode 报错,
AttributeError: 'str' object has no attribute 'decode'

encode 也无法解码显示正确的字符。

解决

req = requests.get(url, headers=headers)
html=req.content
html_doc=str(html,'utf-8')
上一篇下一篇

猜你喜欢

热点阅读