0
点赞
收藏
分享

微信扫一扫

Scrapy中文乱码解决

洛茄 2022-03-12 阅读 95



一、得到html编码方式,一般有:utf-8,GBK,GB2312

方法一:查看标签meta中属性charset的值

方法二:chardet查看

1. 安装chardet:$ pip install chardet

2. 代码:chardet.detect(string)


二、换:GBK,GB2312转utf-8



gbkContent = response.body.decode(chardet.detect(response.body)['encoding'])
utf8Content = gbkContent.encode('utf-8')
print utf8Content



举报

相关推荐

0 条评论