成功解决:UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\xee’ in position 71: illegal multibyte sequence
原始代码
with open('douban.html','r',encoding = 'utf-8') as f:
data = f.read()
f.close()
print(data)
出现的错误
不能读取html文件,尝试过多种编码方式都不能解决,最后在读取的时候使用编码并解码的方式成功解决。(先用gbk编码,忽略掉非法字符,然后再译码)
解决后的代码
with open('douban250.html', 'r', encoding='utf-8'