Example:
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)
How do I get the following(a beautifulsoup object) from soup?
<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>
Simply search for it:
I used the class to limit the find, but since there are no other
pelements that’s a little redundant here.If, instead, you need to remove the tag, use the above method to first find it, then call
.extract()on it to remove it from the document:Two things: the removed tag is returned from the
.extract()method, you could save it for later use. The tag is removed from the document altogether, you’d have to re-add it manually later if you still need it to be in the document anyway.Alternatively, you could use the
.decompose()method, which deletes the tag from the document altogether, without returning a reference. The tag is then gone forever.