Python convert html tags in ampersand format

617 Views Asked by At

I have text in the following format ampersand lt;div ampersand gt;\n ampersand lt;div ampersand gt; ampersand lt;span ampersand gt;Customer.. How can i convert this text to html i.e.

<div>
<div>
<span>
Customer..
1

There are 1 best solutions below

0
On BEST ANSWER

Try:

import html
html_string = "ampersand lt;div ampersand gt;\n ampersand lt;div ampersand gt; ampersand lt;span ampersand gt;Customer..".replace("ampersand ", "&")
html.unescape(html_string)

In case you are looking to maintain new lines:

html.unescape(html_string.replace("\n", "<br />"))