Tech notes

Daily notes about my IT activities.

2013-07-30

python: unescape HTML

by hackprime

#!python
import re
from htmlentitydefs import name2codepoint

def htmlentitydecode(string):
    return re.sub(
        '&(%s);' % '|'.join(name2codepoint),
        lambda m: unichr(name2codepoint[m.group(1)]),
        string)

Source: Escaping HTML - Python Wiki