简体   繁体   English

如何遍历硒列表

[英]How to loop through a selenium list

I've launched my browser which is headless and I've been able to figure out how to login to the website. 我已经启动了无头浏览器,并且能够弄清楚如何登录该网站。 However, I can't figure out how to loop through the now close tree to expand it so all the links on the website can be visible for me to grab. 但是,我无法弄清楚如何遍历现在关闭的树来展开它,以便我可以看到网站上的所有链接。 Is there any ideas or any code that may help me. 有什么想法或代码可以对我有所帮助。

Here is the photo of the closed tree: 这是闭树的照片:

在此处输入图片说明

Here is the photo of the open tree: 这是那棵开阔的树的照片:

在此处输入图片说明

Here is the HTML 这是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>

Grab all the Elements in the all, architecture. 全面掌握架构中的所有元素。 Then use a recursive function until every element is stored in the list. 然后使用递归函数,直到每个元素都存储在列表中。 I do not have the exact code but you can do this: 我没有确切的代码,但是您可以执行以下操作:

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)

This should give you every link. 这应该给您每个链接。 MAke it effivcient by using if/else loops. 通过使用if / else循环使之有效。 It it has helped, let me know. 它帮助了我,让我知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM