9394952

导航

Python解决编码问题: `UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 10

python处理各种跨系统的字符串时,经常会出现各种编码问题,例如linux或网上爬虫多为UTF-8,转到WINDOWS时又需要GBK或GB2312编——这时就经常会出现转换出错 `UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 10

具体原因可参照:https://blog.csdn.net/github_35160620/article/details/53353672

处理方法:https://www.cnblogs.com/cwp-bg/p/7835434.html

我用的最懒人做法:string.decode('utf-8', 'ignore').encode('gbk', 'ignore')

posted on 2020-12-07 08:59  9394952  阅读(306)  评论(0编辑  收藏  举报