【发布时间】:2016-04-05 08:35:05
【问题描述】:
doc = open("1.html").read().strip()
doc = doc.decode("utf-8","ignore")
这个例子没问题。我可以得到正确的 unicode 字符串文档。
doc = open("1.html").read().strip()
if u"charset=utf" in doc or u"charset=\"utf" in doc:
doc = doc.decode("utf-8","ignore")
出现错误“UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 289: ordinal not in range(128)” 任何人都可以解释这个吗?字符串文档可以通过字符串查找来更改吗? 忘了说,1.html里面有中文。
【问题讨论】:
标签: python string unicode encoding utf-8