python爬虫-'gbk' codec can't encode character 'xa0' in position 134: illegal mult
Posted shishibuwan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python爬虫-'gbk' codec can't encode character 'xa0' in position 134: illegal mult相关的知识,希望对你有一定的参考价值。
UnicodeEncodeError Traceback (most recent call last) <ipython-input-95-45a7accf2da0> in <module> 1 fout = open(‘job_desc.txt‘, ‘wt‘) 2 for info in job_desc: ----> 3 fout.write(",\"\"\n".format(info[0],info[1].replace("\n","").replace(" ",""))) 4 fout.close() UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\xa0‘ in position 134: illegal multibyte sequence
运行代码如下,报错如上
fout = open(‘job_desc.txt‘, ‘wt‘) for info in job_desc: fout.write(",\"\"\n".format(info[0],info[1].replace("\n","").replace(" ",""))) fout.close()
解决方法:
fout = open(‘job_desc.txt‘, ‘wt‘,encoding=‘utf-8‘) for info in job_desc: fout.write(",\"\"\n".format(info[0],info[1].replace("\n","").replace(" ",""))) fout.close()
以上是关于python爬虫-'gbk' codec can't encode character 'xa0' in position 134: illegal mult的主要内容,如果未能解决你的问题,请参考以下文章
python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character 'xXX(
UnicodeEncodeError: 'gbk' codec can't encode character 'xa0' in position 9865: (
UnicodeEncodeError: 'gbk' codec can't encode character 'xbb' in position
[python错误]UnicodeDecodeError: 'gbk' codec can't decode byte...