Created
June 9, 2021 15:30
-
-
Save dimitryzub/a52247dfbc79985199b6b6c3c42f0456 to your computer and use it in GitHub Desktop.
Scrape Google Maps Local Results using SerpApi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from serpapi import GoogleSearch | |
import csv | |
params = { | |
"api_key": "YOUR_API_KEY", | |
"engine": "google_maps", | |
"type": "search", | |
"google_domain": "google.com", | |
"q": "кофе мариуполь", # query | |
"ll": "@47.0919234,37.5093148,12z" # @ + latitude + , + longitude + , + zoom | |
} | |
search = GoogleSearch(params) | |
results = search.get_dict() | |
with open('fus_ro_dah.csv', mode='w', encoding='utf8') as csv_file: | |
fieldnames = ['Place name', 'Place type', 'Rating', 'Reviews', 'Price', 'Delivery option', 'Dine in option', 'Takeout option'] | |
writer = csv.DictWriter(csv_file, fieldnames=fieldnames) | |
writer.writeheader() | |
coffee_data = [] | |
for result in results['local_results']: | |
place_name = result['title'] | |
place_type = result['type'] | |
try: | |
rating = result['rating'] | |
except: | |
rating = None | |
try: | |
reviews = result['reviews'] | |
except: | |
reviews = None | |
try: | |
price = result['price'] | |
except: | |
price = None | |
try: | |
delivery_option = result['service_options']['delivery'] | |
except: | |
delivery_option = None | |
try: | |
dine_in_option = result['service_options']['dine_in'] | |
except: | |
dine_in_option = None | |
try: | |
takeout_option = result['service_options']['takeout'] | |
except: | |
takeout_option = None | |
coffee_data.append({ | |
'Place name': place_name, | |
'Place type': place_type, | |
'Rating': rating, | |
'Reviews': reviews, | |
'Price': price, | |
'Delivery option': delivery_option, | |
'Dine in option': dine_in_option, | |
'Takeout option': takeout_option, | |
}) | |
for data in coffee_data: | |
writer.writerow(data) | |
print('Finished') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
i tested your code and im getting only 20 results.
How can i get the pagination working?
thanks!