Python Selenium 网页抓取图表数据

2024-04-27 03:31:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从这个网页上抓取图表数据https://www.focusireland.ie/resource-hub/latest-figures-homelessness-ireland/

在右上方,有一个图表详细说明了爱尔兰无家可归者的数量。在

我试着在网上划出轴,它是Jul-14和它对应的值3258。但是,我无法使用x路径定位这些元素及其值。在

我试过这样的方法来获取价值

Val1 = driver.find_element_by_xpath("//*[@id='chart']/div[7]").text 

没用。在

试过了这:在

^{pr2}$

它对我也不起作用,并返回错误消息作为

Unable to locate an element with the xpath expression //div[@class='label series smaller' | @class='label series smaller hover']/span[text()='Jul-14' because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@class='label series smaller' | @class='label series smaller hover']/span[text()='Jul-14'' is not a valid XPath expression.

Tags: thetotextdiv图表elementxpathlabel
2条回答

您可以尝试以下代码获取文本:

element_to_hover_over = firefox.find_element_by_xpath("//span[text()='Jul-14']")

hover = ActionChains(firefox).move_to_element(element_to_hover_over)
hover.perform()

element_to_hover_over = firefox.find_element_by_xpath("//div[@class='label value outline  showOnHover hover']/span") 

元素\u到\u悬停_超过.text在

您的第二张图表在框架内,首先您需要切换到框架中:-

^{pr2}$

然后尝试在xpath下面获取列表中的值

list <webElement> = (//div[@class='label series smaller' and @data-column='X.1'])[1]/span

然后遍历每一行并获取值

数据不在那个网站上。您必须解析图表()的源iframe数据包装器.dwcdn.net/** ). 然后必须提取并解析JS变量(__数据仓库参数数据). 在

这并不难,see this。在

相关问题 更多 >