【问题标题】:How to ignore tags on beautifulsoup4 python如何忽略beautifulsoup4 python上的标签
【发布时间】:2019-09-22 17:04:16
【问题描述】:
我正在开发一个新项目,但遇到了一些问题。
我的问题就是这样。
<div class="news">
<p class="breaking"> </p>
...
<p> i need to pull here. </p>
但是 class= "break" 是不允许我这样做的。我想忽略“破坏”类并拉动<p>。
【问题讨论】:
标签:
python
python-3.x
beautifulsoup
html-parser
【解决方案1】:
也许,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>]