【发布时间】:2015-01-30 07:52:46
【问题描述】:
我有一个名为test.html 的html 文件,它有一个单词בדיקה。
我打开 test.html 并使用这段代码打印它的内容:
file = open("test.html", "r")
print file.read()
但它打印??????,为什么会发生这种情况,我该如何解决?
顺便说一句。当我打开文本文件时效果很好。
编辑:我试过这个:
>>> import codecs
>>> f = codecs.open("test.html",'r')
>>> print f.read()
?????
【问题讨论】:
-
了解 unicode、UTF-8
-
您需要以 UTF-8 格式打开文件。 stackoverflow.com/questions/491921/…
-
如果仍然无法正常工作,请发布您尝试处理的页面。
标签: python python-2.7 character-encoding