最近遇到爬取网页乱码的情况,找了好久找到了种解决的办法:
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")
最近遇到爬取网页乱码的情况,找了好久找到了种解决的办法:
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")