![](/img/trans.png)
[英]How to extract total search results with Selenium Webdriver in Python?
[英]How to extract the information of Total Confirmed from webpage with selenium webdriver in python
單擊所選國家/地區后,我想從網站頂部獲取“已確認總數”的數量
網站: https : //gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6
下面是我寫的代碼:
poland = driver.find_element_by_xpath("//h5//span[contains(text(),'Poland')]")
poland.click()
要提取數字“1,862”,點擊波蘭不是強制性的,相反,您需要為visibility_of_element_located()
或element_to_be_clickable()
引入WebDriverWait ,您可以使用以下基於xpath的定位器策略:
使用XPATH和 ``:
driver.get('https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6') print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h5//span[contains(text(),'Poland')]//preceding::span[2]/strong"))).text)
控制台輸出:
1,862
使用XPATH和 ``:
driver.get('https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6') print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h5//span[contains(text(),'Poland')]//preceding::span[2]/strong"))).text)
控制台輸出:
1,862
注意:您必須添加以下導入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.