网页格式gbk转utf-8【python requests】


resp = requests.get(url) 

resp.content 是str类型

resp.text是unicode类型

 

如果返回的中文使用gbk编码,需要转换成utf-8的时候:

resp.content.decode('gb2312').encode('utf-8')

resp.content.decode('gb2312')   #从gbk转unicode

resp.content.decode('gb2312').encode('utf-8')  #将unicode编码编译成utf-8


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM