Home > Net >  Python Replace Html Codes With Corresponding Data
Python Replace Html Codes With Corresponding Data

Time:07-15

In Python I am trying to replace the codes '&#8220' and '”' in the string using the replace txt file, I have read many tutorials but cannot come up with a solution. Any help would be greatly appreciated.

replace.txt “ " ” "

string = 'Biden Brags About Handing Out “Record” Number of Work Visas to Foreigners'

CodePudding user response:

Use html library, it has a function to "convert" those character codes to utf-8.

import html

funny_str = "Test &#8220"

print(html.unescape(funny_str))

CodePudding user response:

Use the replace method...

new_string = string.replace('“', '')

and

new_string = string.replace('&#8820', '')
  • Related