1、问题回放:
打开python脚本,敲入下面的命令语句,发现一切正常
>>> import requests
>>> respose = requests.get('https://foofish.net')
>>> respose.status_code
200
>>> respose.reason
'OK'
>>> for name,value in respose.headers.items():
print('%s:%s' %(name,value))
Server:nginx/1.10.2
Date:Thu, 28 Sep 2017 02:48:42 GMT
Content-Type:text/html
Last-Modified:Wed, 27 Sep 2017 09:59:29 GMT
Transfer-Encoding:chunked
Connection:keep-alive
Vary:Accept-Encoding
ETag:W/"59cb7681-283c"
Strict-Transport-Security:max-age=15768000
Content-Encoding:gzip
>>> respose.content
<!DOCTYPE html>\n<html lang="zh-cmn-hans">\n。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。<li><a href="http://weibo.com/lzjun567" target="_blank">\xe5\xbe\xae\xe5\x8d\x9a</a></li>\n 。。。。</html>
当我用respose.content 输出请求的内容时,发现中文全部变成了这样。。。。什么鬼,太不友好吧
然后:
>>> respose.content.decode('utf-8')
恩,将上面的内容加上编码格式,问题解决了,当然还有其他的解决方法,如果你看到了,欢迎留言告知,谢谢,共同进步