2
例子:如何選擇一切,但使用beautifulsoup4某個html元素?
import bs4
html = '''
<div class="short-description std ">
<em>Android Apps Security</em> provides guiding principles for how to
best design and develop Android apps with security in mind. The book explores
techniques that developers can use to build additional layers of security into
their apps beyond the security controls provided by Android itself.
<p class="scroll-down">∨ <a href="#main-desc" onclick="Effect.ScrollTo(
'main-desc', { duration:'0.2'}); return false;">Full Description</a> ∨</p></div>
'''
soup = bs4.BeautifulSoup(html)
我如何從soup
以下(一beautifulsoup對象)?
<div class="short-description std ">
<em>Android Apps Security</em> provides guiding principles for how to
best design and develop Android apps with security in mind. The book explores
techniques that developers can use to build additional layers of security into
their apps beyond the security controls provided by Android itself.
</div>
對不起Martijn,標題中的問題是正確的,但我錯過了這個例子中的問題。我編輯它,它應該是**除了'p'元素**,而不是**''p'元素**。你的答案只是獲得'p'元素。 – Bentley4
@ Bentley4:關於你期望的結果和你想要對剩下的部分做什麼,這個問題仍然是模棱兩可的。您的問題仍然不正確,要過濾* out *,但'p'元素只能選擇'p'元素。我懷疑你想要另一種方式。 –
我用*過濾*作爲* select *的同義詞。所以我想要的是選擇除了'p'元素之外的所有東西。我改變了過濾器在問題中選擇。 – Bentley4