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

ps:

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

2.常用的中文编码名称

python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
参考文章:http://blog.csdn.net/jim7424994/article/details/22675759

上一篇:CentOS7+Mono5.2.0.224 +Jexus5.8.3.0 布署 Asp.Net MVC (vs2017)


下一篇:Android Studio项目整合PullToRefresh的问题记录