Python - Requests 中文

Python - Requests 中文

Max.Bai

2017-04-21


记录Requests 请求返回带中文问题:

decode  string to unicode
encode  unicode to string


1. windows:

windows 上先要把得到的结果转为unicode,再转码到gb2312 就可以直接显示中文

print res.content.decode('utf-8').encode('gb2312')


或者直接转码到iso-8859 再到unicode,再到gb2312

res.text.encode('iso-8859-1').decode('utf-8').encode('gb2312')



2. linux上面就比较简单

res.text.encode('iso-8859-1')
res.content


猜你喜欢

转载自blog.csdn.net/max229max/article/details/70316652