I have a html text like this:
<xml ... >
and I want to convert it to something readable:
<xml ...>
Any easy (and fast) way to do it in Python?
With the help of html. escape() method, we can convert the html script into a string by replacing special characters with the string with ascii characters by using html. escape() method. Return : Return a string of ascii character script from html.
The html. unescape() method helps us to convert the ascii string into html script by replacing ascii characters with special HTML characters. This tool will convert HTML entities to a string or convert plain text to HTML entities.
Official documentation for HTMLParser
: Python 3
>>> from html import unescape
>>> unescape('© €')
© €
Official documentation for HTMLParser
: Python 3
>>> from html.parser import HTMLParser
>>> pars = HTMLParser()
>>> pars.unescape('© €')
© €
Note: this was deprecated in the favor of html.unescape()
.
Official documentation for HTMLParser
: Python 2.7
>>> import HTMLParser
>>> pars = HTMLParser.HTMLParser()
>>> pars.unescape('© €')
u'\xa9 \u20ac'
>>> print _
© €
Modern Python 3 approach:
>>> import html
>>> html.unescape('© €')
© €
https://docs.python.org/3/library/html.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With