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")

 

posted on 2016-10-20 17:33  细雨微光  阅读(689)  评论(0编辑  收藏  举报