Search code examples
pythonhtmlpython-2.7decodepretty-print

Decode HTML string using python 2.7


I want the following HTML string to be decoded with HTML tags

\u003cp\u003e\u003cstrong\u003e\u003cspan\u003eAbout the Company \u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e

How can I do that in Python 2.7 ?

I am having large HTML string to decode. The above sample is just a apart of that.

PS: I have tried with many solutions available in web to decode HTML string but nothing helps me EDIT: I have referred this https://stackoverflow.com/a/2087433/4350834 and got the result as

\u003cp\u003e\u003cstrong\u003e\u003cspan\u003eAbout the Company \u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e

Solution

  • You can try:

    >>>text = "\u003cp\u003e\u003cstrong\u003e\u003cspan\u003eAbout the Company \u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e".decode('unicode-escape')
    >>>print text
    u'<p><strong><span>About the Company </span></strong></p>'