您的位置:首页 > 编程语言 > Python开发

Python HTTP库requests中文页面乱码解决方案!

2017-06-28 11:15 141 查看

把html编码类型赋与获取到文本

获取html编码类型:

1.使用apparent_encoding可以获得真实编码

1 >>> response.apparent_encoding
2 'GB2312'

2.从html的meta中抽取

1 >>> requests.utils.get_encodings_from_content(response.text)
2 ['gb2312']

前戏结束,只出一招即可(随意选用):

1 # response.encoding = response.apparent_encoding
2 response.encoding = 'gb2312

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: