【发布时间】:2013-07-19 16:48:55
【问题描述】:
我想将 HTML 实体转换回人类可读的格式,例如'£' 到 '£','°' 到 '°' 等等。
我已经阅读了几篇关于这个问题的帖子
Converting html source content into readable format with Python 2.x
Decode HTML entities in Python string?
Convert XML/HTML Entities into Unicode String in Python
据他们说,我选择使用未记录的函数 unescape(),但它对我不起作用...
我的代码示例如下:
import HTMLParser
htmlParser = HTMLParser.HTMLParser()
decoded = htmlParser.unescape('© 2013')
print decoded
当我运行这个 python 脚本时,输出仍然是:
© 2013
而不是
© 2013
我正在使用 Python 2.X,在 Windows 7 和 Cygwin 控制台上工作。我用谷歌搜索并没有发现任何类似的问题..有人可以帮我解决这个问题吗?
【问题讨论】:
-
我已经尝试从命令行和 IDLE 调用它,它确实对我有用(Windows 8 上的 Python 2.7)。