在python2环境下:
response.text是unicode数据类型,而response.content是字符串类型
python2环境下数据类型
分别查看response.text和response.content的内容
接下来分别print response.text和response.content的内容,发现response.content可以正常显示
,而response.text依然是乱码,为了解决这一问题可以查看下默认的编码方式
默认编码方式
设置编码方式为utf-8
r.encoding='utf-8' #此处写成utf8也可以
然后分别print r.text和r.content可以看到文字部分显示正常
在python3环境下:
response.text是str数据类型,而response.content是bytes类型
python3环境下数据类型