-1

I am trying to get the positions cx and cyfrom <circle> elements using selenium in python, but I haven't found any way to do it. That is how the website and the HTML looks like: enter image description here

Does anyone know how to get all the cx and cy values from all the circles within the <g> in the image?

scraper
  • 39
  • 6

2 Answers2

2

You can use get_attribute

cx,cy = [],[]
circle = driver.find_elements_by_tag_name('circle')
for i in circle:
    cx.append(i.get_attribute('cx'))
    cy.append(i.get_attribute('cy'))
Ananth
  • 623
  • 2
  • 9
0

Borrowed from "Extract value of attribute node via XPath":

driver.find_element_by_xpath("path/to/circle/element/@cx")

and

driver.find_element_by_xpath"path/to/circle/element/@cy")

Update: response to comment

For selecting all cx-attributes, use something like this:

path_to_circles = "//div[@class='g-act'/div/div/div/svg/g/g/circle"
cx_values = driver.find_element_by_xpath(path_to_circles + "/@cx").extract()
cy_values = driver.find_element_by_xpath(path_to_circles + "/@cy").extract()

Then you probably also want to change the values from string to float:

cx_values = [float(cx) for cx in cx_values]
cy_values = [float(cy) for cy in cy_values]

And probably turn them into list of pairs (i.e. [(50.23, 115.36), ...]):

values_from_graph = list(zip(cx_values, cy_values))

Note that I didn't test the code so please excuse me for any typos :)

Toivo Mattila
  • 325
  • 1
  • 7