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

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

2016-10-20 17:33 239 查看
最近遇到爬取网页乱码的情况,找了好久找到了种解决的办法:

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