0% found this document useful (0 votes)
123 views

How To Scrape Data From Google Maps Using Python - GeeksforGeeks

Uploaded by

wilsont9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views

How To Scrape Data From Google Maps Using Python - GeeksforGeeks

Uploaded by

wilsont9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

1 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

Download Right Now

Download Right Now Download

2 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

# Import the library Selenium


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# Make browser open in background


options = webdriver.ChromeOptions()
options.add_argument('headless')

# Create the webdriver object


browser = webdriver.Chrome(
executable_path="C:\chromedriver_win32\chromedriver.exe",
options=options)

# Obtain the Google Map URL


url = ["https://www.google.com/maps/place/\
Papa+John's+Pizza/@40.7936551,-74.0124687,17z/data=!3m1!4b1!\
4m5!3m4!1s0x89c2580eaa74451b:0x15d743e4f841e5ed!8m2!3d40.\
7936551!4d-74.0124687", "https://www.google.com/maps/place/\
Lucky+Dhaba/@30.653792,76.8165233,17z/data=!3m1!4b1!4m5!3m4!\
1s0x390feb3e3de1a031:0x862036ab85567f75!8m2!3d30.653792!4d76.818712"]
# Initialize variables and declare it 0
i = 0

# Create a loop for obtaining data from URLs


for i in range(len(url)):

# Open the Google Map URL

3 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

browser.get(url[i])

# Obtain the title of that place


title = browser.find_element_by_class_name(
"x3AX1-LfntMc-header-title-title")
print(i+1, "-", title.text)

# Obtain the ratings of that place


stars = browser.find_element_by_class_name("aMPvhf-fI6EEc-KVuj8d")
print("The stars of restaurant are:", stars.text)
print("\n")

1 - Papa Johns Pizza


The stars of restaurant are: 3.6

2 - Lucky Da Dhaba
The stars of restaurant are: 3.8

# Import the library Selenium


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# Make browser open in background


options = webdriver.ChromeOptions()
options.add_argument('headless')

# Create the webdriver object


browser = webdriver.Chrome(
executable_path="C:\chromedriver_win32\chromedriver.exe",
options=options)

# Obtain the Google Map URL


url = ["https://www.google.com/maps/place/\
Papa+John's+Pizza/@40.7936551,-74.0124687,17z/data=!3m1!4b1!\
4m5!3m4!1s0x89c2580eaa74451b:0x15d743e4f841e5ed!8m2!3d40.\
7936551!4d-74.0124687", "https://www.google.com/maps/place/\

4 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

Lucky+Dhaba/@30.653792,76.8165233,17z/data=!3m1!4b1!4m5!3m4!\
1s0x390feb3e3de1a031:0x862036ab85567f75!8m2!3d30.653792!4d76.818712"]

# Initialize variables and declare it 0


i = 0

# Create a loop for obtaining data from URLs


for i in range(len(url)):

# Open the Google Map URL


browser.get(url[i])

# Obtain the title of that place


title = browser.find_element_by_class_name(
"x3AX1-LfntMc-header-title-title")
print(i+1, "-", title.text)

# Obtain the address of that place


address = browser.find_elements_by_class_name("CsEnBe")[0]
print("Address: ", address.text)
print("\n")

# Import the library Selenium


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

5 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

# Make browser open in background


options = webdriver.ChromeOptions()
options.add_argument('headless')

# Create the webdriver object


browser = webdriver.Chrome(
executable_path="C:\chromedriver_win32\chromedriver.exe",
options=options)

# Obtain the Google Map URL


url = ["https://www.google.com/maps/place/\
Papa+John's+Pizza/@40.7936551,-74.0124687,17z/data=!3m1!4b1!\
4m5!3m4!1s0x89c2580eaa74451b:0x15d743e4f841e5ed!8m2!3d40.\
7936551!4d-74.0124687", "https://www.google.com/maps/place/\
Lucky+Dhaba/@30.653792,76.8165233,17z/data=!3m1!4b1!4m5!3m4!\
1s0x390feb3e3de1a031:0x862036ab85567f75!8m2!3d30.653792!4d76.818712"]

# Initialize variables and declare it 0


i = 0

# Create a loop for obtaining data from URLs


for i in range(len(url)):

# Open the Google Map URL


browser.get(url[i])

# Obtain the title of that place


title = browser.find_element_by_class_name(
"x3AX1-LfntMc-header-title-title")
print(i+1, "-", title.text)

# Obtain the contact number of that place


phone = browser.find_elements_by_class_name("CsEnBe")[-2]
print("Contact Number: ", phone.text)
print("\n")

1 - Papa Johns Pizza


Contact Number: +1 201-662-7272

2 - Lucky Da Dhaba
Contact Number: 095922 67185

6 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

# Import the library Selenium


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# Make browser open in background


options = webdriver.ChromeOptions()
options.add_argument('headless')

# Create the webdriver object


browser = webdriver.Chrome(
executable_path="C:\chromedriver_win32\chromedriver.exe",
options=options)

# Obtain the Google Map URL


url = ["https://www.google.com/maps/place/\
Papa+John's+Pizza/@40.7936551,-74.0124687,17z/data=!3m1!4b1!\
4m5!3m4!1s0x89c2580eaa74451b:0x15d743e4f841e5ed!8m2!3d40.\
7936551!4d-74.0124687", "https://www.google.com/maps/place/\
Lucky+Dhaba/@30.653792,76.8165233,17z/data=!3m1!4b1!4m5!3m4!\
1s0x390feb3e3de1a031:0x862036ab85567f75!8m2!3d30.653792!4d76.818712"]

# Initialize variables and declare it 0


i = 0

# Create a loop for obtaining data from URLs


for i in range(len(url)):

# Open the Google Map URL


browser.get(url[i])

# Obtain the title of that place


title = browser.find_element_by_class_name(
"x3AX1-LfntMc-header-title-title")
print(i+1, "-", title.text)

# Obtain the reviews of that place


review = browser.find_elements_by_class_name("OXD3gb")
print("------------------------ Reviews --------------------")
for j in review:
print(j.text)
print("\n")

7 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

# Import the library Selenium


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# Make browser open in background


options = webdriver.ChromeOptions()
options.add_argument('headless')

# Create the webdriver object


browser = webdriver.Chrome(
executable_path="C:\chromedriver_win32\chromedriver.exe",
options=options)

# Obtain the Google Map URL


url = ["https://www.google.com/maps/place/\
Papa+John's+Pizza/@40.7936551,-74.0124687,17z/data=!3m1!4b1!\
4m5!3m4!1s0x89c2580eaa74451b:0x15d743e4f841e5ed!8m2!3d40.\
7936551!4d-74.0124687", "https://www.google.com/maps/place/\
Lucky+Dhaba/@30.653792,76.8165233,17z/data=!3m1!4b1!4m5!3m4!\
1s0x390feb3e3de1a031:0x862036ab85567f75!8m2!3d30.653792!4d76.818712"]

# Initialize variables and declare it 0

8 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

i = 0

# Create a loop for obtaining data from URLs


for i in range(len(url)):

# Open the Google Map URL


browser.get(url[i])

# Obtain the title of that place


title = browser.find_element_by_class_name(
"x3AX1-LfntMc-header-title-title")
print(i+1, "-", title.text)

# Obtain the ratings of that place


stars = browser.find_element_by_class_name("aMPvhf-fI6EEc-KVuj8d")
print("The stars of restaurant are:", stars.text)

# Obtain the description of that place


description = browser.find_element_by_class_name("uxOu9-sTGRBb-T3yXSc")
print("Description: ", description.text)

# Obtain the address of that place


address = browser.find_elements_by_class_name("CsEnBe")[0]
print("Address: ", address.text)

# Obtain the contact number of that place


phone = browser.find_elements_by_class_name("CsEnBe")[-2]
print("Contact Number: ", phone.text)

# Obtain the reviews of that place


review = browser.find_elements_by_class_name("OXD3gb")
print("------------------------ Reviews --------------------")
for j in review:
print(j.text)
print("\n")

9 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

10 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

11 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

12 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

13 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

14 of 15 16-02-2024, 12:22 pm
How to scrape data from google maps using Python ? - GeeksforGeeks https://www.geeksforgeeks.org/how-to-scrape-data-from-google-maps...

15 of 15 16-02-2024, 12:22 pm

You might also like