【问题标题】:How do I get the value between the start and end tag Python Selenium?如何获取开始和结束标签 Python Selenium 之间的值?
【发布时间】:2021-07-20 15:59:56
【问题描述】:

我正在尝试自动从此 HTML 标记中获取值:

<span data-testid="TemperatureValue" class="CurrentConditions--tempValue--1RYJJ">84°</span>
中间的温度值自动变化。

另外,我应该为 find_element_by_xpath() 变量使用 XPath 还是完整的 Xpath?

【问题讨论】:

    标签: python html selenium web-scraping


    【解决方案1】:

    试试这个

    degree = driver.find_element_by_xpath("//*[@data-testid='TemperatureValue']").text
    
    print(degree)
    

    【讨论】:

    • 说没有getAttribute()方法
    • 现在可以查一下吗
    【解决方案2】:

    使用

    driver.find_element_by_css_selector('span[data-testid="TemperatureValue"]').text
    

    将其存储在变量中并打印出来

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2011-06-07
      • 2016-05-24
      • 1970-01-01
      • 2023-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多