开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜