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.
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
Asked: 2023-07-10 07:37:14 +0000
Seen: 8 times
Last updated: Jul 10 '23
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?