Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Beautifulsoup中的嵌套汤_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python Beautifulsoup中的嵌套汤

Python Beautifulsoup中的嵌套汤,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,为了真正正确地处理这些数据,我希望能够用Python制作一个嵌套的汤 例如,在.Net中,我会执行以下操作: For Each node As HtmlNode In document.DocumentNode.SelectNodes("//tr[@class='ClassName']") For Each SecondNode As HtmlNode In node.SelectNodes(".//span[@class='SecondClassName']") 因此,我可以解析使用Beau

为了真正正确地处理这些数据,我希望能够用Python制作一个嵌套的汤

例如,在.Net中,我会执行以下操作:

For Each node As HtmlNode In document.DocumentNode.SelectNodes("//tr[@class='ClassName']")
For Each SecondNode As HtmlNode In node.SelectNodes(".//span[@class='SecondClassName']")
因此,我可以解析使用BeautifulSoup已经找到的每个部分中的元素

我正在尝试这样的事情:

soup = BeautifulSoup(WebDriver.page_source, "html5lib")
for EachSection in soup.find_all("tr", {"class" : "ClassName"}):
 soup2 = BeautifulSoup(EachSection, "html5lib")
 print soup2
第一部分工作。我可以通过打印转储每个节的代码,也可以通过get_text()获取内容,但第二部分导致了问题

它抛出:

TypeError: 'NoneType' object is not callable
我知道我可以直接将第一道汤发送到Span/SecondClassName,但它会在.Net无法读取的地方读取换行符,我可能需要使用一些容易出错的解析来获取所需的一切

有办法做到这一点吗

/编辑:

我一直在玩各种各样的游戏:

if EachSection.parent.name == 'div':
  print EachSection["tr"]

我都不知道我找对地方了还没找到。不过,这似乎是一种更整洁的做事方式。

我不知道为什么我的脑子里把这件事复杂化了。不需要创建另一个汤,只需为该部分创建另一个for循环

这很好:

for EachSection2 in EachSection("span", {"class" : "SecondClassName"}):

为什么这会正确处理数据?