Ask Your Question
1

How can I extract the thumbnail/photo URL and other data from Google Map using Selenium Scraper?

asked 2023-07-10 07:37:14 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-07-10 08:06:01 +0000

djk gravatar image

Here's an example code to extract the thumbnail/photo URL and other data from Google Map using Selenium Scraper in Python:

from selenium import webdriver

# Set up the webdriver and open Google Maps
driver = webdriver.Chrome()
driver.get('https://www.google.com/maps')

# Search for the place you're interested in
search_box = driver.find_element_by_id('searchboxinput')
search_box.send_keys('San Francisco')
search_box.submit()

# Wait for the maps to load and switch to the first result
driver.implicitly_wait(10)
first_result = driver.find_element_by_css_selector('div.section-result:nth-child(1)')
first_result.click()

# Wait for the place details to load and get the thumbnail/photo URL and other data
driver.implicitly_wait(10)
thumbnail_url = driver.find_element_by_css_selector('img.section-hero-header-image-hero').get_attribute('src')
name = driver.find_element_by_css_selector('h1.section-hero-header-title-title').text
address = driver.find_element_by_css_selector('div[data-item-id="address"]').text
rating = driver.find_element_by_css_selector('span.section-star-display').text

# Print the results
print('Name:', name)
print('Address:', address)
print('Rating:', rating)
print('Thumbnail URL:', thumbnail_url)

# Close the webdriver
driver.quit()

This script opens Google Maps, searches for "San Francisco", clicks on the first result, waits for the place details to load, and then extracts the thumbnail/photo URL, name, address, and rating. You can modify this script to search for other places and extract different information as needed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-10 07:37:14 +0000

Seen: 8 times

Last updated: Jul 10 '23