我正在做一个新项目,但我遇到了一些问题。我的问题就是这样。<div class="news"> <p class="breaking"> </p> ...<p> i need to pull here. </p>但是 class = "break" 是不允许我这样做的。我想忽略“破坏”类并拉动<p>.
1 回答

胡说叔叔
TA贡献1804条经验 获得超8个赞
也许,class=''会做find_allor 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>]
添加回答
举报
0/150
提交
取消