python 文件写入错误

在保存网页文字到txt文件下时,出现如下错误

UnicodeEncodeError: 'gbk' codec can't encode character u'\xa9' in position 24051: illegal multibyte sequence

解决方法:

with open(“d:/1.txt”,‘a’,encoding=‘gb18030’) as f:

GB18030是GBK的父集,所以能兼容GBK不能编码的字符

上一篇:ecstore 安装后提示require function does not exist in....


下一篇:LeetCode37 Sudoku Solver