VBA到Python转换使用beautifulsoup

页面源代码

For Each hdiv In doc.getElementsByClassName("offset1 transport-plan location-detail well well-white margin20right") For Each child In hdiv.Children If child.tagName = "H4" Then location = child.innerText ElseIf child.tagName = "TABLE" Then If row.tagName = "TBODY" Then For Each row1 In row.Children do something If row1.tagName = "TR" Then For Each row2 In row1.Children If row2.innerText <> "" Then activity = row2.innerText 

如何使用Beautifulsoup将此VBA代码转换为Python

只想了解如何build立孩子的关系

我正在尝试像下面的东西

 soup = BeautifulSoup(driver.page_source) for each_div in soup.findAll("div", { "class" : "offset1 transport-plan location-detail well well-white margin20right" }): children = each_div.findChildren() for child in children: if child.name == "H4": print(child.text) elif child.name == "TABLE": print (child.text)