如何忽略 beautifulsoup4 python 上的标签

How to ignore tags on beautifulsoup4 python

我正在做一个新项目,遇到了一些问题。

我的问题就是这样。

<div class="news">
      <p class="breaking">  </p>
      ...
<p> i need to pull here. </p>

但是class="breaking"是不让我去做的。我想忽略 class "breaking" 并拉 <p>.

也许,class='' 可以用 find_allfindAll:

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>]