加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python爬虫-'gbk' codec can't encode ch

发布时间:2020-12-20 12:54:42 所属栏目:Python 来源:网络整理
导读: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 "
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("{},"")))
fout.close()

解决方法:

fout = open(job_desc.txt,wt,encoding=‘utf-8‘)
for info in job_desc:
    fout.write("{},"")))
fout.close()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读