I’m trying to scrape search results from google maps. However once I enter my search, the results come up in a portion of the frame with a scroll bar not a part of the entire body. I need to click on a consistently appearing text (such as “Results”) after my search is entered to activate the part of the website where the scroll bar is so I can send by down keys to automatically scroll down.
def search_industry_and_scroll(driver, industry):
driver.get('https://www.google.com/maps')
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'searchboxinput')))
search_input = driver.find_element(By.ID, 'searchboxinput')
search_input.send_keys(industry)
search_input.send_keys(Keys.RETURN)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div.Nv2PK.THOPZb')))
# Click on the div element after the search
div_to_click = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.vasquette.id-app-container'))
)
div_to_click.click()
# Scroll down the page
body = driver.find_element(By.TAG_NAME, 'body')
while True:
body.send_keys(Keys.PAGE_DOWN)
time.sleep(2) # Wait for new elements to load
New contributor
Ty Gelman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.