open的参数encoding设置成'utf-8'试试,如果反复换编码都报错,errors= 'ignore'(或'replace' )还有用with语句吧,这样不笔手动对文件对象close了最后'html'不是好的变量命名 with open('douban.txt','w',encoding='utf-8',errors='replace') as f: f.write(html) print( "写入的内容:",open('douban.txt','r').read() )
open的参数encoding设置成'utf-8'试试,如果反复换编码都报错,errors= 'ignore'(或'replace' )
还有用with语句吧,这样不笔手动对文件对象close了
最后'html'不是好的变量命名