kaihami
kaihami

Reputation: 815

Selenium JS map scrape with Python

I'm new with Selenium, actually I'm trying it since yesterday, found some stuff interesting with Selenium with python.

I found some information regarding how to scrape and interact with JS page. But my doubt is how can I get a data from a clickable map with selenium. I tried to found if there are any hidden links in the page, but there aren't any of them. I figured out that when I move my mouse over the map in any button (in the map) there is a change in x,y position (of course...) and after I click in the button I can scrape my data. Using a static model I could scrape all the data that I want.

So my question is, how can I simulate the mouse movement over the map and this click action?

Best regards,

Upvotes: 0

Views: 814

Answers (1)

Andersson
Andersson

Reputation: 52665

If you have x,y position on map and length, width of map, then you can try something like

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.your_web_page.com") # specify webpage
element=driver.find_elements_by_xpath("provide_map_selector") # specify correct xpath
x = 25 # set actual value
y = 50 # set actual value
length = 500 # set actual value
width = 300 # set actual value
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(element, width - y, length - x)
action.click()
action.perform()

Upvotes: 1

Related Questions