使用 BeautifulSoup 删除不必要的重复标签

sau*_*abh 5 python beautifulsoup

我正在使用 Python 和 BeautifulSoup 从 html 中提取一些文本。我有一些包含表单文本的 html

<h3><b> Abc </b><b> DEF </b> </h3>
Run Code Online (Sandbox Code Playgroud)

我想删除重复的 b 标签。有没有快速的方法来做到这一点?

dus*_*ual 2

对于 bs4 这似乎工作得很好

In [4]: soup.h3
Out[4]: <h3><b> Abc </b><b> DEF </b> </h3>

In [5]: soup.h3.text
Out[5]: u' Abc  DEF  '
Run Code Online (Sandbox Code Playgroud)

在此处查看文档和包: https://beautiful-soup-4.readthedocs.org/en/latest/ https://pypi.python.org/pypi/beautifulsoup4