Python 3.4+Strings (str)function
html.unescape()
HTML escaping
Turns HTML entities (<, &, ©, ©, A) back into characters — the inverse of html.escape.
Syntax
html.unescape(s)
Parsing follows the HTML5 rules rather than "up to the semicolon": legacy entities such as & and ¬ are recognised without a ;, so the string '¬it;' becomes '¬it;'. The function knows all 2000+ named entities, including — it becomes the non-breaking space '\xa0', which is not equal to ' ', so comparisons with a plain space fail. To parse a whole page use html.parser, not unescape.
Examples
import html
print(html.unescape('<b> © © A')) # → <b> © © A
print(html.unescape('¬it;')) # → ¬it; — ¬ узнан без точки с запятой
print(html.unescape('a b') == 'a b') # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy