Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dimitryzub/a52247dfbc79985199b6b6c3c42f0456 to your computer and use it in GitHub Desktop.
Save dimitryzub/a52247dfbc79985199b6b6c3c42f0456 to your computer and use it in GitHub Desktop.
Scrape Google Maps Local Results using SerpApi
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')
@djmystica
Copy link

Hi!
i tested your code and im getting only 20 results.
How can i get the pagination working?
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment