【问题标题】:Is there a certain depth which can be set with find_elements in selenium?硒中的find_elements是否可以设置一定的深度?
【发布时间】:2021-06-29 16:33:47
【问题描述】:

是否可以限制 selenium python 中 find_elements 的深度。例如

element = driver.find_elements_by_tag_name(„li“)

# This is what would be saved
<ul>
<li>
  #smth
  <ul>
  <li>…</li>
  <li>…</li>
  </ul>
</li>

<li>
  #smth
  <ul>
  <li>…</li>
  <li>…</li>
  </ul>
</li>

</ul>

这里的 element 将包括外部列表,但也包括内部列表(列表中的列表)。

是不是只能拿到外层的

  • 【问题讨论】:

    • 你尝试过这个建议吗?
    • 不,在等待答案的过程中我去睡觉了,第二天我找到了更好的方法来解决我的问题,所以我没有尝试。

    标签: python html selenium selenium-webdriver element


    【解决方案1】:

    driver.find_element_by_css_selector("li:first-of-type") 可能会解决您的问题。

    【讨论】:

    • 试试这个定位器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多