python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

python实现爬虫遇到编码问题:

error:UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

解决办法:改变标准输出

添加代码:

sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030') #改变标准输出的默认编码

python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX_第1张图片

ps:

1.str转bytes叫encode,bytes转str叫decode

2.常用的中文编码名称

python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX_第2张图片

参考文章:http://blog.csdn.net/jim7424994/article/details/22675759


你可能感兴趣的:(【python】)