Unicode equal comparison failed to convert both arguments to Unicode - interpreting问题解决

在写python爬虫时,在

if s.get('item_name') == '性别':
    sex = s.get('item_content')

这段代码的地方出现了上面的问题,意思是字符编码的问题,然后在网上查了一下,推荐的解决方式是

import sys

reload(sys)
sys.setdefaultencoding('utf8')

在代码前面添加如上几句语句,问题得以解决。

参考自:https://blog.csdn.net/xiongwanfeng/article/details/78019429

Guess you like

Origin blog.csdn.net/kr2563/article/details/84594789