python问题解决----把\xe6\xa8\xa1\这种字符转为普通汉字?

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

恩,将上面的内容加上编码格式,问题解决了,当然还有其他的解决方法,如果你看到了,欢迎留言告知,谢谢,共同进步

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值