/ Published in: Python

ex : decode_htmlentities("l'eau")
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
from htmlentitydefs import name2codepoint as n2cp import re def substitute_entity(match): ent = match.group(3) if match.group(1) == "#": if match.group(2) == '': return unichr(int(ent)) elif match.group(2) == 'x': return unichr(int('0x'+ent, 16)) else: cp = n2cp.get(ent) if cp: return unichr(cp) else: return match.group() def decode_htmlentities(string): entity_re = re.compile(r'&(#?)(x?)(\w+);') return entity_re.subn(substitute_entity, string)[0]
Comments
