Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dimitryzub/4a5c1d1b0ed9046c30bba2ac0f18f6bb to your computer and use it in GitHub Desktop.
Save dimitryzub/4a5c1d1b0ed9046c30bba2ac0f18f6bb to your computer and use it in GitHub Desktop.
Scrape Google Maps Local Results with Python and SerpApi
from serpapi import GoogleSearch
import json
params = {
"api_key": "YOUR-API-KEY", # your serpapi api key
"engine": "google_maps", # serpapi search engine
"type": "search", # type of the search. Search, Place..
"q": "Burger", # search query
"hl": "en", # language of the search
"ll": "@47.6080482,-122.3074315,13z" # GPS coordinates of location to search places from
}
search = GoogleSearch(params) # where data extraction happens on the backend
results = search.get_dict() # JSON -> Python dictionary
local_results_plcaes = []
if not "error" in results:
for result in results.get("local_results"):
local_results_plcaes.append({
"place_name": result.get("title"),
"rating": result.get("rating"),
"reviews": result.get("reviews"),
"place_id": result.get("place_id"),
"address": result.get("address"),
"phone": result.get("phone"),
"website": result.get("website"),
"reviews_link": result.get("reviews_link"),
"photos_link": result.get("photos_link"),
"gps_coordinates": result.get("gps_coordinates"),
"thumbnail": result.get("thumbnail")
# many other types of data
})
else:
print(results["error"])
print(json.dumps(local_results_plcaes, indent=2, ensure_ascii=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment