使用 BeautifulSoup 查找顶级标签
我正在看一些 BeautifulSoup 。在这种情况下,我的树如下所示:
soup = "<table class="myTable"><tr>...</tr></table>"
当我调用以下命令时:
soup.findAll(attrs={'class':'myTable'})
当我期望返回顶级标记时,我没有返回任何内容。但是,如果我要搜索的标签不在顶层,如下所示:
soup = "<body><table class="myTable"><tr>...</tr></table></body>"
然后我会找到该表。我想我错过了一些明显的东西。如果我不是,有没有办法找到所有内容,包括顶级标签?
I have some BeautifulSoup I'm looking at. In this case, my tree looks like this:
soup = "<table class="myTable"><tr>...</tr></table>"
When I call the following:
soup.findAll(attrs={'class':'myTable'})
I don't have anything returned, when I would expect that top level tag to be returned. But if the tag I'm searching for isn't in the top level, like the following:
soup = "<body><table class="myTable"><tr>...</tr></table></body>"
Then I do find the table. I assume I'm missing something obvious. If I'm not, is there a way to have find everything including the top level tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法重现该问题。我认为找到顶级标签应该有效:
I can't reproduce the problem. I think finding the top-level tags should work: