Nitin
Nitin

Reputation: 2642

Python convert html tags in ampersand format

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..

Upvotes: 0

Views: 651

Answers (1)

Moses Koledoye
Moses Koledoye

Reputation: 78564

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 />"))

Upvotes: 1

Related Questions