How to convert XML/HTML entities into Unicode string in Python?

Sometimes, we want to convert XML/HTML entities into Unicode string in Python.

In this article, we’ll look at how to convert XML/HTML entities into Unicode string in Python.

How to convert XML/HTML entities into Unicode string in Python?

To convert XML/HTML entities into Unicode string in Python, we can use the html.unescape method.

For instance, we write

import html

a = html.unescape('©')
b = html.unescape('©')

to call html.unescape with strings to decode the string with the XML or HTML entities into Unicode strings.

Conclusion

To convert XML/HTML entities into Unicode string in Python, we can use the html.unescape method.