簡體   English   中英

如何獲取 Python Selenium 開始和結束標記之間的值?

[英]How do I get the value between the start and end tag Python Selenium?

我正在嘗試自動從此 HTML 標記中獲取值:

 <span data-testid="TemperatureValue" class="CurrentConditions--tempValue--1RYJJ">84°</span>
中間的溫度值自動變化。

另外,我應該為 find_element_by_xpath() 變量使用 XPath 還是完整的 Xpath?

試試這個

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

print(degree)

采用

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

將其存儲在變量中並打印

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM