简体   繁体   中英

How to get data from a website using python selenium

i am trying to fetch data from a svg element(graph). iam using x path with name() functionality but still it is returning empty strings.. my code from python was

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)

let me know if i am missing any thing... i want to answers

  1. how to retrive the data in "d" element in the path class(highlitd)
  2. by writing the python code entire tag is getting highlited i want only the values with "d" im quite new to html and python please help me out

You can directly access the element and print the text value ( unless it is hidden behind a 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM