我正在做一個新項目,但我遇到了一些問題。我的問題就是這樣。<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
提交
取消