孩子们,来个bs4.Beautulsoup吗?

2024-10-02 00:20:18 发布

您现在位置:Python中文网/ 问答频道 /正文

.children方法返回一个Python列表(请参阅最后一行包含的代码),而我想要的是soupy;如果我能得到一个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>]

Tags: 对象noindivhtmloutareposts

热门问题