我正在做一個(gè)新項(xiàng)目,但我遇到了一些問(wèn)題。我的問(wèn)題就是這樣。<div class="news"> <p class="breaking"> </p> ...<p> i need to pull here. </p>但是 class = "break" 是不允許我這樣做的。我想忽略“破壞”類(lèi)并拉動(dòng)<p>.
1 回答

胡說(shuō)叔叔
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊
也許,class=''會(huì)做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>]
添加回答
舉報(bào)
0/150
提交
取消