【问题标题】:Python Selenium - Looping through child elementsPython Selenium - 循环遍历子元素
【发布时间】:2021-02-27 02:37:45
【问题描述】:

如何循环遍历“ctbdy”的元素并检查“bl_name bln_end”是否为“Materials”?

【问题讨论】:

  • link = [div.p for div in soup.find_all('div', attrs={'class' : 'ctbdy'})] 将为您提供p 标签,您可以从那里获得span.text
  • 如果是材料你想做什么?

标签: python selenium loops element


【解决方案1】:

如果所有 span 元素具有相同的类名。获取元素跨度列表。然后使用循环逐个检查跨度文本。

list_span_elements = driver.find_elements_by_xpath("//div[@class='ctbdy']/p/span[@class='bl_name bln_end']")
for element in list_span_elements:
    if (element.text == "Materials"):
        print("Find element with Materials")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 2016-05-29
    相关资源
    最近更新 更多