Scrape Google Maps - scroll down with Selenium

Viewed 58

So I'm trying to use Selenium to scrape Google Maps for websites links (employment agencies from the particular area of Poland):

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

region = 'Gdańsk' #location
url = 'https://www.google.com/maps/search/employment+agency+near+'+region
driver.get(url) #open Google Maps

acceptButton = driver.find_element("xpath", "//*[@id='yDmH0d']/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/div[1]/form[2]/div/div/button")
acceptButton.click() #accept cookies

links=driver.find_elements(By.CLASS_NAME,'lcr4fd') #locate the first set of businesses in the left panel with the browsing results
for link in links:
print(link.get_attribute("href")) #get the links from the top results

element = driver.find_element(By.CLASS_NAME,'hfpxzc') #locate the first result in the left panel
ActionChains(driver).move_to_element(element).click().perform() #click to focus pointer where I want to scroll down

Whole code here

Now I'm trying to scroll down, but to no avail. Already tried:

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 

from here and:

for i in range(5): #driver.find_element(By.TAG_NAME,'body').send_keys(Keys.END)

from here. This thread looks similar, but I'm finding no solution. Here's the video of how the code runs in VSC & Chrome. Any help?

0 Answers
Related