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


