我正在尝试使用pythonbeautifulsoup4库解析一个大型html文档。在
页面包含一个非常大的表,其结构如下:
<table summary='foo'>
<tbody>
<tr>
A bunch of data
</tr>
<tr>
More data
</tr>
.
.
.
100s of <tr> tags later
</tbody>
</table>
我有一个函数,用于评估soup.descendants
中的给定标记是否是我要查找的类型。这是必要的,因为页面很大(beauthulsoup告诉我文档包含大约4000个标记)。
是这样的:
我的问题是,当我迭代soup.descendants
时,当我知道<tr>
标记继续存在数百行时,函数只为表中的前77行返回{
这是我的函数有问题还是有什么我不明白的关于beauthoulsoup如何生成它的后代集合的?我怀疑这可能是Python或bs4内存问题,但我不知道如何进行故障排除。在
更像是一个有教养的猜测,但我会试试看。在
BeautifulSoup
解析HTML的方式很大程度上取决于underlying parser。如果您不specify it explicitly,BeautifulSoup
将根据内部排名自动选择一个:在您的情况下,我会尝试切换解析器,看看您会得到什么结果:
相关问题 更多 >
编程相关推荐