如何循环浏览

2024-04-25 15:13:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经启动了我的浏览器,这是无头的,我已经能够想出如何登录到该网站。然而,我不知道如何循环通过现在关闭的树来扩展它,这样网站上的所有链接都可以被我看到。有什么想法或代码可以帮助我。你知道吗

这是封闭的树的照片:

enter image description here

这是这棵树的照片:

enter image description here

这是HTML

<div id="index__tree" class="index__tree">
<ul class="idx">
<li class="closed"><div class="li"><a href="/doku.php?id=start&amp;idx=all" title="all" class="idx_dir"><strong>all</strong></a> 
</div></li>
<li class="closed"><div class="li"><a href="/doku.php?id=start&amp;idx=architecture" title="architecture" class="idx_dir"> 
<strong>architecture</strong></a></div></li>

Tags: dividtreeindex网站liall照片
1条回答
网友
1楼 · 发布于 2024-04-25 15:13:36

抓住建筑中的所有元素。然后使用递归函数,直到每个元素都存储在列表中。我没有确切的代码,但您可以这样做:

1-> parent_A=driver.find_elements_by___your choice___()
2-> parent_B=driver.find_elements_by___your choice___()
3-> Make a list of all the links. all_links=[]
4-> for new_child in parent_A:
      x=new_child.find_elements_by___your choice___().get_attribute('href')
      if x not in all_links:
         all_links.append(x)
         parent_A.append(x)

这应该给你每一个环节。通过使用if/else循环使其更高效。它有帮助,让我知道。你知道吗

相关问题 更多 >