python - 如何忽略beautifulsoup4 python上的标签
问题描述
我正在做一个新项目,但我遇到了一些问题。
我的问题就是这样。
<div class="news">
<p class="breaking"> </p>
...
<p> i need to pull here. </p>
但是 class = "break" 是不允许我这样做的。我想忽略“破坏”类并拉动<p>
.
解决方案
也许,class=''
会做find_all
or 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>]
推荐阅读
- multithreading - Delphi:当与来自另一个线程的数据交互时,如何使 VCL 控件成为线程安全的?
- java - IntelliJ - 解决 Maven 工件
- javascript - 如何使用 JavaScript 附加 HTML 代码?
- xaml - nuget 中的 UWP 样式和主题找不到资源文件
- openapi - Swagger codegen:生成具有正确名称的数组元素
- java - 通过终端使用 jasypt 加密简单字符串
- android - 如何查找 Android 类引入了哪个 API 级别?
- reactjs - 在反应中从另一个钩子调用钩子
- c++ - std::filebuf 打开文件,如果不存在则创建
- python - BeautifulSoup 允许我抓取一些文章,但不能抓取其他文章(来自同一份报纸)