1

I am trying to web-scrape the chart data from this page https://www.focusireland.ie/resource-hub/latest-figures-homelessness-ireland/

On the right top, there is a chart which details Number of homeless people in Ireland.

I am trying to web-scrape the axis which is Jul - 14 and it's corresponding value 3258. But, I couldn't do locate those element and it's value using x-path.

I tried something like this to web-scrape the value

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

& it didn't work.

And tried this:-

element_to_hover_over = driver.find_element_by_xpath("//div[@class='label series smaller' | @class='label series smaller hover']/span[text()='Jul-14'").text
print(element_to_hover_over)

It didn't work either for me and returned an error message as

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.

2 Answers2

1

Tha data are not on that website. You have to parse source iframe of the chart ( datawrapper.dwcdn.net/** ). Then you have to extract and parse JS variable (__dw.params.data).

This is not so hard, see this.

Nestor Yanchuk
  • 1,186
  • 8
  • 10
1

You can try below code to get text :

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") 

element_to_hover_over.text

Your second chart is inside frame first you need to switch into frame :-

frame :- datawrapper-chart-8ZOKk

then try below xpath to get value in list

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

then iterate through every row and get value

Ankur Singh
  • 1,239
  • 1
  • 8
  • 18