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)