在这个网页https://meshb.nlm.nih.gov/treeView中,我想遍历树的每个节点,如果我在它们的项目中看到单词“carvodiary…”,我想创建一个字典,列出顶级节点以及所有心血管相关项目。例如,在上面的页面中,您可以看到如果您展开“解剖学[A]”,您将看到心血管。现在,我想要这一部分,以及任何包含在心血管系统中的东西,如果你扩展它的话。我希望遍历html页的某些元素的一部分如下所示:
<a class="ng-scope">
<span class="ng-binding ng-scope">Anatomy [A]</span>
</a>
<ul class="treeItem ng-scope">
<li class ="ng-scope" >
< a class ="ng-scope" href="/record/ui?ui=D001829" >
< span class ="ng-binding ng-scope" > Body Regions[A01] < / span >
</a>
</li>
< li class ="ng-scope" >
<a class ="ng-scope" href="/record/ui?ui=D001829" >
< span class ="ng-binding ng-scope" > Cardio Vascular< / span >
</a>
<ul class="treeItem ng-scope">
<li class="ng-scope">
<a class="ng-scope" href="/record/ui?ui=D015824">
<span class="ng-binding ng-scope">Blood-Air Barrier [A07.025]</span>
</a>
<ul class="treeItem ng-scope">
<li class="ng-scope">
<a class="ng-scope" href="/record/ui?ui=D018916">
<span class="ng-binding ng-scope">Blood-Aqueous Barrier [A07.030]</span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
。。。。。 这就是我目前所能做到的!在Python中,作为第一步,我想遍历顶级节点并找到单词“carvenous..”,但我一直看到错误“no such element:Unable to locate element”。有人能告诉我我错过了什么吗?你知道吗
from selenium import webdriver
chrome_path=r"G:\My Drive\A\chrome_driver\chromedriver_win32\chromedriver.exe"
driver=webdriver.Chrome(chrome_path)
driver.get('https://meshb.nlm.nih.gov/treeView')
for links in driver.find_elements_by_css_selector('a.ng-scope'):
cardio = links.find_element_by_css_selector('li>a>span.ng-binding.ng-scope')
print(cardio.text)
你的代码中有一些问题。除非单击父节点上的“+”图标,否则不能遍历列表。你知道吗
在您的代码中,我可以看到您已经创建了一个包含父节点(如解剖学、有机体等)的列表,但是您还没有编写扩展该列表的代码。你知道吗
您必须遵循以下步骤:
我已经为您创建了一个代码,包括第一、第二和第三步。请以同样的方式进行。你知道吗
我有java的背景,所以请原谅我的任何语言相关的语法问题。你知道吗
相关问题 更多 >
编程相关推荐