python(27)requests 爬取网页乱码,解决方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python(27)requests 爬取网页乱码,解决方法相关的知识,希望对你有一定的参考价值。

最近遇到爬取网页乱码的情况,找了好久找到了种解决的办法:

html = requests.get(url,headers = head)
html.apparent_encoding
html.encoding = html.apparent_encoding
print html.text

头文件中添加:

import sys
reload(sys)
sys.setdefaultencoding("utf-8")

 

以上是关于python(27)requests 爬取网页乱码,解决方法的主要内容,如果未能解决你的问题,请参考以下文章