python - 如何忽略 beautifulsoup4 python 上的标签

标签 python python-3.x beautifulsoup html-parser

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

我的问题就是这样。

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

但是 class = "break"不让我这么做。我想忽略“破坏”类并拉出 <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>]

关于python - 如何忽略 beautifulsoup4 python 上的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58051523/

相关文章:

python - 在python中基于Dataframe创建文件夹

python - 有没有办法检查我的代码的哪一部分使文件句柄处于打开状态

Python - 更新 GUI,使其始终使用更新后的列表

python - 如何在 Pandas 系列中获取下一个非 NaN 数字的索引?

python - 类型错误 : Argument given by name ('k' ) and position (2)

python-3.x - 将新创建的文件夹的名称放在 csv 文件的路径中

python - NoneType 对象不可调用__美汤

python - 循环访问 BeautifulSoup 中的元素,但仅输出该元素的子元素

python - 如何提取文本直到美丽汤中的 <br> 标签

python - 使用OpenCV从图像中提取所选区域