开发者

Finding Top Level Tags With BeautifulSoup

开发者 https://www.devze.com 2023-03-29 12:04 出处:网络
I have some BeautifulSoup I\'m looking at. In this case, my tree looks like this: soup = \"<table class=\"myTable\"><tr>...</tr></table>\"

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?


I can't reproduce the problem. I think finding the top-level tags should work:

In [92]: import BeautifulSoup
In [94]: soup=BeautifulSoup.BeautifulSoup('<table class="myTable"><tr>...</tr></table>')

In [95]: soup.findAll(attrs={'class':'myTable'})
Out[95]: [<table class="myTable"><tr>...</tr></table>]
0

精彩评论

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