UnicodeEncodeError: 'gbk' codec can't encode character 'xee'

Posted zzqc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UnicodeEncodeError: 'gbk' codec can't encode character 'xee'相关的知识,希望对你有一定的参考价值。

  在将爬取到的内容写入文件时候报了这个错误,解决方案是在open()的时候给encoding参数传‘utf-8‘就好了,因为网页的编码就是utf-8。

 

1 with open(douban.html,w,encoding=utf-8) as f:
2      f.write(res.text)

 

以上是关于UnicodeEncodeError: 'gbk' codec can't encode character 'xee'的主要内容,如果未能解决你的问题,请参考以下文章

UnicodeEncodeError: 'ascii' codec can't encode character u'u5929' in position 2(

UnicodeEncodeError: 'ascii' codec can't encode characters

UnicodeEncodeError: 'ascii' codec can't encode characters in

UnicodeEncodeError: 'gbk' codec can't encode character 'xbb' in position

UnicodeEncodeError: 'ascii' codec can't encode character...的解决方法

UnicodeEncodeError: 'gbk' codec can't encode character 'u25aa' in position 15: (