首页 > 编程语言 > 详细

python2使用re匹配报错:TraitError

时间:2021-04-02 21:54:20      阅读:16      评论:0      收藏:0      [点我收藏+]

错误信息

TraitError: Could not decode ‘re.findall("\xe6\x9d\xa5\xe6\xba\x90\xef\xbc\x9a(.*)", web_source_info.encode("utf-8"))‘ for unicode trait ‘_i00‘ of a HistoryManager instance.

原因是网站的源码 编码格式不对

改下网站源码编码再匹配即可

root = Selector(type="html",text=response.body.decode(‘gb2312‘))
web_source_info=""
web_source_arr = re.findall(u"来源:(.*)", web_source_info)

python2使用re匹配报错:TraitError

原文:https://www.cnblogs.com/c-x-a/p/14611863.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!