Remplacer les entités html avec les UTF-8 correspondants en caractères Python 2.6
-
06-09-2019 - |
Question
J'ai un texte html comme ceci:
<xml ... >
et je veux le convertir en quelque chose de lisible:
<xml ...>
De toute façon facile (et rapide) de le faire en Python?
La solution
Python 2.7
Documentation officielle pour HTMLParser
: Python 2.7
>>> import HTMLParser
>>> pars = HTMLParser.HTMLParser()
>>> pars.unescape('© €')
u'\xa9 \u20ac'
>>> print _
© €
Python 3
Documentation officielle pour HTMLParser
: Python 3
>>> from html.parser import HTMLParser
>>> pars = HTMLParser()
>>> pars.unescape('© €')
© €
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow