簡體   English   中英

如何使用python selenium從網站獲取數據

[英]How to get data from a website using python selenium

我正在嘗試從 svg 元素(圖形)中獲取數據。 我使用帶有 name() 功能的 x 路徑,但它仍然返回空字符串..我的 python 代碼是

outer_html_1 = self.driver.find_elements(By.XPATH,"//*[local-name()='svg' and @class='nvd3-svg']//*[local-name()='g' and @class='nvd3 nv-wrap nv-lineChart']//*[local-name()='g' and @class='nv-focus']//*[local-name()='g' and @class='nvd3 nv-wrap nv-line']//*[local-name()='g']//*[local-name()='g' and @class='nv-groups']//*[local-name()='g' and @class='nv-group nv-series-2']//*[local-name()='path' and @class='nv-line']")
 print(outer_html_1)

如果我遺漏了什么,請告訴我......我想回答

  1. 如何檢索路徑類中“d”元素中的數據(highlitd)
  2. 通過編寫 python 代碼,整個標簽都被高亮了,我只想要帶有“d”的值,我對 html 和 python 還很陌生,請幫幫我

您可以直接訪問元素並打印文本值(除非它隱藏在 iframe 后面)。

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


data = WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH, "//g/path[@class='nv-line']")))
print(data.get_attribute("d"))

# This should print the value from the attribute "d"

暫無
暫無

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

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