得到一个bs4.BeautifulSoup由.children?

时间:2015-01-28 14:09:24

标签: python beautifulsoup

.children方法返回一个 Python列表(参见包含代码的最后一行),而我想要一些浓汤;如果我能得到一个bs4.BeautifulSoup对象可以对孩子们进行find和其他操作。

bs4.BeautifulSoup似乎是唯一可以包含兄弟标记的对象。如何与孩子们建立一个多汁的数据结构?

In [123]: a._soup
Out[123]: 
<div guppy-html="no-posts">There are <i>literally</i> no posts to show you</div>
<div><p guppy-html="text"></p></div>

In [120]: type(a._soup)
Out[120]: bs4.BeautifulSoup

In [129]: list(a._soup.children)
Out[129]: 
[<div guppy-html="no-posts">There are <i>literally</i> no posts to show you</div>,
 u'\n',
 <div><p guppy-html="text"></p></div>]

0 个答案:

没有答案