开发者

BeautifulSoup and find

开发者 https://www.devze.com 2023-03-14 23:04 出处:网络
I have a html code: <div id=\'div1\'> <div id=\'d\'> </div> <p></p> </div>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消