BeautifulSoup and find
I have a html code:
<div id='div1'>
<div id='d'> </div>
<p></p>
</div>
How do I get all that in a div with an id div1? soup.find('div',{'id':"div1"}) ret开发者_如何转开发urns:
<div id='div1'>
<div id='d'> </div>
<p></p>
</div>
I need to get only:
<div id='d'> </div>
<p></p>
See the documentation, specifically .find()
and .contents
.
You want the content between the start and end of the tag including all child tags.
soup.find('div', id="div1").contents
精彩评论