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

把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