【问题标题】: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)
【解决方案2】:
使用
driver.find_element_by_css_selector('span[data-testid="TemperatureValue"]').text
将其存储在变量中并打印出来