我正在开发一个新项目,但遇到了一些问题。
我的问题就是这样。
<div class="news">
<p class="breaking"> </p>
...
<p> i need to pull here. </p>
但是 class = "break"不让我这么做。我想忽略“破坏”类并拉出 <p>
.
最佳答案
也许,class=''
可以使用 find_all
或 findAll
:
from bs4 import BeautifulSoup
html = """
<div class="news">
<p class="breaking"> </p>
...
<p> i need to pull here. </p>
"""
soup = BeautifulSoup(html, 'html.parser')
print(soup.find_all('p', class_=''))
print(soup.findAll(True, {'class': ''}))
输出
[<p> i need to pull here. </p>]
[<p> i need to pull here. </p>]
关于python - 如何忽略 beautifulsoup4 python 上的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58051523/