Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Scrape Google Map? [closed]

Sorry for this question, I am new to this.

I have a project where I need to scrape Google Maps to find all the companies in a region, I just heard about the term when we decided on the project, I have done some research and have found out that most scraping services require a certain company field to start the search but I need ALL companies in that area, Can someone explain how I should start?

I saw that in this thread : Is it ok to scrape data from Google results?

they talk about IP's I know that ISP's allocate public IP addresses to certain regions, but how do I go about using that to scrape?

Also I came across an article that said I had to use Google API but on their website : https://developers.google.com/maps/web-services/ which API should I use?

I am using Ubuntu system, if I need to install anything should I use a windows OS instead?

thanks and kind regards

UPDATE :

I found from http://py-googlemaps.sourceforge.net/ that I could use this python code :

local = gmaps.local_search('cafe near ' + destination) print local['responseData']['results'][0]['titleNoFormatting'] Vie De France Bakery & Cafe

If I replace Cafe by "Companies" or whatever name I believe I will get the information I am looking for right? Also I was wondering if someone could tell me how to go about getting into the configuration interface?

like image 687
BeachSamurai Avatar asked Apr 11 '16 03:04

BeachSamurai


People also ask

Is it legal to scrape Google Maps?

Yes, scraping data from Google Maps is legal. You can use the official Google Maps API to extract data from Google Maps. However, it limits how much data you can scrape from the website. Using Google Maps crawlers and web scraping tools is an efficient way to do so.

How do I extract an embedded Google map?

You can access the full google map by clicking the "View Larger Map" icon in the upper right corner of the map embedded on the page you shared. Here is the url. In the google map, if you go to the top of the legend and click the three vertical dots, the menu will display the option "Download KML".


1 Answers

You can use google-search-results package to scrape Google Maps.

Full example at Repl.it.

import os
from serpapi import GoogleSearch

params = {
    "engine": "google_maps",
    "q": "coffee",
    "type": "search",
    "ll": "@40.7455096,-74.0083012,14z",
    "api_key": os.getenv("API_KEY")
}

client = GoogleSearch(params)
data = client.get_dict()

print("Local results")

for result in data['local_results']:
    print(f"""
Title: {result['title']}
Address: {result['address']}
Rating: {result['rating']}
Reviews: {result['reviews']}""")

if 'ads_results' in data:
    print("Ads")

    for result in data['ads_results']:
        print(f"""
Title: {result['title']}
Address: {result['address']}""")

JSON Response

{
  "local_results": [
    {
      "position": 1,
      "title": "Birch Coffee",
      "data_id": "0x89c258ef40975c2b:0x4fa24ff965c3f3e",
      "gps_coordinates": {
        "latitude": 40.7638094,
        "longitude": -73.9666075
      },
      "rating": 4.5,
      "reviews": 477,
      "price": "$$",
      "type": "Coffee shop",
      "address": "134 1/2 E 62nd St, New York, NY 10065",
      "hours": "Open until 7:00 PM",
      "phone": "(212) 686-1444",
      "website": "http://www.birchcoffee.com/",
      "description": "Hip spot offering house-roasted brews. Local coffeehouse chain serving thoughtfully-sourced, house-roasted brews in a hip, bustling space.",
      "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipPy035-T0IVHuC3CffD8UEf0n70HkkZXvkb7gSJ=w122-h92-k-no"
    },
    {
      "position": 2,
      "title": "Think Coffee",
      "data_id": "0x89c259ca0a28731f:0xd3d13e0daf7fae6c",
      "gps_coordinates": {
        "latitude": 40.7522222,
        "longitude": -74.0016667
      },
      "rating": 3.9,
      "reviews": 467,
      "price": "$$",
      "type": "Coffee shop",
      "address": "500 W 30th St, New York, NY 10001",
      "website": "http://www.thinkcoffee.com/",
      "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipMIVRZJMr-bnGKw28VTrctmhVYQOnIKBRj0NmnN=w122-h92-k-no"
    }
    
    // Stripped...
  ]
}

Output

Local results
Title: Think Coffee
Address: 73 8th Ave, New York, NY 10014
Rating: 4.2
Reviews: 741

Title: Birch Coffee @Flatiron
Address: 21 E 27th St, New York, NY 10016
Rating: 4.4
Reviews: 940

Title: Irving Farm New York
Address: 135 E 50th St, New York, NY 10022
Rating: 4.3
Reviews: 248

// Stripped...

Ads
Title: Gotham Coffee Roasters
Address: 23 W 19th St, New York, NY 10011

Disclosure: I work at SerpApi.

like image 200
Ilya Zub Avatar answered Sep 21 '22 13:09

Ilya Zub