DEV Community

Cover image for SerpApi's Google Maps Scraper
Terry Tan
Terry Tan

Posted on • Originally published at serpapi.com

SerpApi's Google Maps Scraper

In SerpApi, we make web scraping on search engines easy and fast. Google Maps Scraper API is one of our customers' favourite to scrape local business, it provides comprehensive google maps data.

SerpApi's Google Maps Playground

It only takes one API call to retrieve all the data available in Google Maps. Above is an example from our playground (Try it out). Upon sign up, you will receive 100 free searches every month.

What type of data can I extract from the Google Maps API?

  • Title - Name of the business entity
  • GPS Coordinates - An accurate GPS coordinates of the business entity
  • Rating - Rating of the business entity
  • Reviews - Total number of reviews of the business entity
  • Price - For some business (e.g. restaurant), price indicate the estimated cost of a meal
  • Type - The business entity type
  • Address - Human readable full address of the business entity
  • Operating Hours - The opening and closing hours of the business from Monday to Sunday
  • Phone - Phone number of the business entity
  • Website - Website URL of the business entity
  • Description - A short summary about the business entity
  • Service Options - Indicate of the business entity offers Dine In, Takeout, Delivery, and many others
  • Order Online - Order URL of the business entity
  • Menu - Menu URL of the business entity
  • Thumbnail - Image of the business entity
  • User Review - Featured review at the front page
  • Amenities - Amenities of the business entity
  • Photos - Get all the user posted photos with pagination. Refer to Google Maps Photos API
  • Reviews - Get all the user reviews with pagination. Refer to Google Maps Reviews API
  • Extensions - Highlights for the business entity (e.g. Fast service, Great coffee, Popular for Breakfast, Wheelchair accessible entrance and many more)
  • People Also Search For - Popular search of a similar business entity

We also provide a few more Google Maps Scraper APIs, which are Google Autocomplete API, Google Contributor Reviews API and Google Directions API.

How to scrape Google Maps?

Here is a step-by-step tutorial on using SerpApi’s Google Maps API to retrieve Google Maps data.

Step 1: Go to SerpApi's Google Maps Playground
The playground is the most intuitive tool to get started. You can feel no different from searching in Google Maps.

SerpApi's Google Maps Playground

The link should direct you to Google Maps. Please verify that it is correctly set to Google Maps.

SerpApi's Playground engine selection

Step 2: Enter the search query and GPS Coordinates to scrape

SerpApi's Playground inputs

Search query can be anything you will usually search in Google Maps. GPS Coordinates is optional, however, we recommend to always search with a GPS Coordinates for higher accurate results. You can find GPS Coordinates from a place using www.gps-coordinates.net or any tool you can find online.

Step 3: Start the search
The search would take averagely 2.5s (or less than 1 second if you are on Ludicrous Speed plan). The results are presented in JSON format with a preview at the left side. Feel free to test more variations of the search query to see if the data matches your needs.

SerpApi's Playground results

At the top right corner - Export to Code, you can copy the JSON URL or follow the code to integrate with your workflow. You do have to register a free SerpApi account to use the API. The HTML can be useful when you would like to inspect the data.

SerpApi's Playground integration

Example in Python

If you would like to straight dive into the code, this should be helpful to get you started on Google Maps data extraction. We also provide many others programming languages (e.g. Javascript, Java, etc), checkout our integration guide.

First, you need to install the SerpApi client library (Github).

pip install google-search-results
Enter fullscreen mode Exit fullscreen mode

Set up the SerpApi credentials and search.

from serpapi import GoogleSearch
import os, json

params = {
    'api_key': 'YOUR_API_KEY',         # your serpapi api
    'engine': 'google_maps',           # SerpApi search engine  
    'q': 'Coffee',                     # query
    'location': "New York, NY, USA"    # location
}
Enter fullscreen mode Exit fullscreen mode

To retrieve the Google Maps local results for a given search query, you can use the following code:

results = GoogleSearch(params).get_dict()['local_results']
Enter fullscreen mode Exit fullscreen mode

You can store Google Maps local results JSON data in databases or export them to a CSV file.

import csv

header = ['position', 'title', 'place_id', 'address', 'rating', 'reviews', 'price', 'phone']

with open('google_maps_results.csv', 'w', encoding='UTF8', newline='') as f:
    writer = csv.writer(f)

    writer.writerow(header)

    for item in results:
        print(item)
        writer.writerow([item.get('position'), item.get('title'), item.get('place_id'), item.get('address'), item.get('rating'), item.get('review'), item.get('price'), item.get('phone')])
Enter fullscreen mode Exit fullscreen mode

FAQs

Is it legal to extract data from Google Maps?
Scraping public available data is generally safe provided the use cases is legal. Refer to our blog post (Scraping public pages is legal in the US) for more information.

Why use SerpApi?
There are some common challenges when scraping huge amounts of data from Google Maps: bypassing CAPTCHAs, IP blocking, rate limits, session timeouts, dynamic web structure, pagination and infinite scrolling, data variability complexity, data parsing and labelling, and legal and ethical considerations. Fortunately you don't need to tackle these problems yourself. SerpApi takes care of them and provides high-quality Google Map Search Results APIs for your usage by using high quality proxies. SerpApi saves you a lot of time so you can concentrate on your business as scraping Google Maps data and other Google search results should be easy.

Am I able to get all of the businesses in a particular city/country?
Getting all the businesses in a specific city or country is possible through our API. But, you will still need a way to list all of the specific businesses. If you already have that list, you can just submit each business name as a search on our API. If not, you can search for that specific business in each city or local subdivision of the country using our API until you build up a list that you’re happy with.

Is there a no-code solution?
Yes, you can use our API in Google Sheets using our SerpApi extension in Google Sheets. We have a comprehensive tutorial for you.

We strive to provide the best SERP scraper out there. Other than the Google Maps data scraper, you can find abundance of Google APIs, Bing APIs, and etc, feel free to checkout SerpApi for more details. Also if you have any questions, please feel free to contact me.

Top comments (0)