Search code examples
pythonstringencodinghtml-escape-characters

Decode chars like &apos into plaintext


So, this is driving me nuts. How can I convert encoded characters like %apos to plaintext? Using Python 3.9.

What I Tried:

string = 'The guy blasts the other guy on 'Russia's Newsroom': 'Totally unfit' to be vice chancellor'

new_string = string.encode('utf-8', 'ignore')

print(new_string)

Solution

  • This has nothing to do with Unicode. It's HTML.

    import html
    print(html.unescape('''))