简体   繁体   English

如何使用python selenium从网站获取数据

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

i am trying to fetch data from a svg element(graph).我正在尝试从 svg 元素(图形)中获取数据。 iam using x path with name() functionality but still it is returning empty strings.. my code from python was我使用带有 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)

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)如何检索路径类中“d”元素中的数据(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通过编写 python 代码,整个标签都被高亮了,我只想要带有“d”的值,我对 html 和 python 还很陌生,请帮帮我

You can directly access the element and print the text value ( unless it is hidden behind a iframe).您可以直接访问元素并打印文本值(除非它隐藏在 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.

相关问题 在python中使用硒从动态网站获取数据:如何发现数据库查询的完成方式? - Using selenium in python to get data from dynamic website: how to discover the way databases querys are done? 如何使用硒python一步一步单击以从网站获取数据 - How to click one by one to get data from website by using selenium python 如何在 Python 3 中使用 Selenium 从网站的某个部分获取文本 - How to get text from a section of a website using Selenium in Python 3 如何使用 Selenium 和 Python 从网站以数字形式获取价格 - How to get the price as a number from a website using Selenium and Python 如何使用python + Selenium从网站保存数据 - How to save data from website by using python + selenium 如何使用python和selenium将数据从列表输入网站? - How to type data from list to a website using python and selenium? 使用 python 中的 selenium 从网站获取价值 - Get value from a website using selenium in python 如何使用 selenium 从网站抓取数据 - How to scrape data from website using selenium 尝试在python2.7中使用Selenium获取网站日历数据 - Trying to get website calendar data using Selenium in python2.7 如何在python中使用selenium从javascript渲染表中获取数据 - How to get data from javascript rendered table using selenium in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM