Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python替换HTML转义字符?_Python - Fatal编程技术网

如何使用Python替换HTML转义字符?

如何使用Python替换HTML转义字符?,python,Python,可能重复: 我有一个满是HTML转义字符的字符串,如“,”,和,

可能重复:

我有一个满是HTML转义字符的字符串,如
,和

有没有Python库为我提供了可靠的方法来用它们各自的实际字符替换所有这些转义字符

例如,我希望所有的
都替换为“s”。

您希望使用以下内容:

try:
    from html.parser import HTMLParser  # Python 3
except ModuleNotFoundError:
    from HTMLParser import HTMLParser  # Python 2
parser = HTMLParser()
html_decoded_string = parser.unescape(html_encoded_string)
我也看到了很多对美的热爱

from BeautifulSoup import BeautifulSoup
html_decoded_string = BeautifulSoup(html_encoded_string, convertEntities=BeautifulSoup.HTML_ENTITIES)
另外,这些现有问题的副本:


使用Beautiful Soup:如果你知道它是重复的,为什么不打旗子而不是回答(代表除外)?当人们没有花时间去寻找他们问题的现有答案时,这很烦人,尤其是在这种情况下,当有这么多精确的副本时。然而,我觉得社区有时会溢出。如果我们误解了这个问题,而它真的不是一个副本呢?如果我回答这个问题引发了一场有意义的对话呢将问题和答案带向另一个方向的假设/线索?这也不是关于声誉的问题,一旦问题被关闭或删除,与之相关的声誉可能会被否定……我只是想提醒你关于StackOverflow上普遍接受的行为准则。如果你似乎有点在意,我会查阅Meta ques我不想争论这个问题,我只是个信使,照你的意愿去做:)。使用
beautifulsoup4==4.6.0
和py3,这应该是
pip安装beautifulsoup4
,然后从bs4导入beautifulsou;html\u decoded\u string=beautifulsoulSoup(x,“lxml”);print(html_decoded_string.string)
在Python 3中,这应该是html.parser导入HTMLParser的