繁体   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