python2.7 requests获取内容中文乱码

  1. html = requests.get(url,headers = head)
  2. html.apparent_encoding
  3. html.encoding = html.apparent_encoding
  4. print html.text

不要指定为utf-8,从apparent_encoding内读,缺省为utf-8就好了

文件头加:

  1. import sys
  2. reload(sys)
  3. sys.setdefaultencoding(“utf-8”)