![](/img/trans.png)
[英]Using selenium in python to get data from dynamic website: how to discover the way databases querys are done?
[英]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)
如果我遗漏了什么,请告诉我......我想回答
您可以直接访问元素并打印文本值(除非它隐藏在 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.