Python 3.4以上用途
html.unescape():
import htmlprint(html.unescape('£682m'))FYI
html.parser.HTMLParser.unescape已过时,并且应该在3.5中删除,尽管它是错误地遗忘的。它将很快从语言中删除。
Python 2.6-3.3
您可以HTMLParser.unescape()从标准库中使用:
- 对于python 2.6-2.7 HTMLParser
- 对于Python 3 html.parser
>>> try:... # Python 2.6-2.7 ... from HTMLParser import HTMLParser... except importError:... # Python 3... from html.parser import HTMLParser... >>> h = HTMLParser()>>> print(h.unescape('£682m'))£682m您还可以使用six兼容性库来简化导入:
>>> from six.moves.html_parser import HTMLParser>>> h = HTMLParser()>>> print(h.unescape('£682m'))£682m


