Table des matières

Google Maps Scraping In Pure Python​

Scraping Google Maps requires good knowledge of coding, browser emulation, proxies, and reCAPTCHA solver. Additionally, you should also be ready to deal with changes that Google might make to its dynamic content.

First of all, you will need to mimic the real user’s behavior by using browser emulation. Using Sélénium or other browser emulators might be a good solution.

Secondly, if you want to keep your office/home IP safe you will need to use proxies. So you can request websites from other people’s IPs.

Even with that set of tools, once you have some good usage, Google might show you reCAPTCHA and bind it to some of your IPs. If you do not want to change IPs every time you see a reCAPTCHA, you can add a reCAPTCHA solver.

Additionally, be prepared for situations when Google might change its content. You can do it by running daily tests.

Although it might take some time to implement the scraper, it can be built and maintained. Check out this step-by-step tutorial on how to scrape Google Maps using Python and Selenium to learn more: How to Scrape Google Maps With Python and Selenium.

Google Maps Scraping With Outscraper Python Package

A more simple and reliable way of scraping Google Maps will be using the Outscraper python library. It provides convenient access to the Outscraper API from applications written in the Python language which allows you to use Outscraper’s services from your code.

You can start by installing the package and creating an account at grattoir.

Google Maps Scraping en Python

Installation

Install the Outscraper SDK by running the following command (Python 3+ is required):

				
					pip install outscraper
				
			

Initialisation

Initialisez le client Outscraper en important la classe et en ajoutant votre clé API secrète. Vous pouvez générer la clé API sur la page de profil.

				
					from outscraper import ApiClient

client = ApiClient(api_key='SECRET_API_KEY')
				
			

Exemples d'utilisation

Voici des exemples de la façon dont vous pouvez extraire des lieux de Google Maps en utilisant des requêtes de recherche :

				
					# Recherche d'entreprises dans des lieux spécifiques :
results = client.google_maps_search_v2(['restaurants brooklyn usa'], limit=20, language='en', region='us')

# Recherche de lieux par deux requêtes
résultats = client.google_maps_search_v2(
    ['restaurants brooklyn usa', 'bars brooklyn usa'],
    limit=50, # limite de lieux pour chaque requête
    language='en',
    region='US',
)

# Itérer sur les résultats
for query_places in results :
    for place in query_places :
        print('query:', place['query'])
        print('name:', place['name'])
        print('phone:', place['phone'])
        print('site web:', place['site'])
				
			

Il est également possible d'extraire les données en utilisant Place Id :

				
					# Get data of the specific place by id
results = client.google_maps_search_v2(['ChIJrc9T9fpYwokRdvjYRHT8nI4'], language='en')

# Scrap Places by Place Ids
results = client.google_maps_search_v2(
    ["ChIJ8ccnM7dbwokRy-pTMsdgvS4", "ChIJN5X_gWdZwokRck9rk2guJ1M", "ChIJxWLy8DlawokR1jvfXUPSTUE"],
    limit=1, # limit of palces per each query
)

# Iterate over the results
for query_places in results:
    for place in query_places:
        print('name:', place['name'])
        print('place_id:', place['place_id'])
				
			

Try Outscraper SDK Now

The Outscraper SDK is available for you to easily do Google Maps Scraping with Python. You can try it right now with a Free Tier.

FAQ

Questions et réponses les plus fréquentes

You can scrape Google Map results by using Outscraper SDK. Specify search queries, language, and other parameters, and send your request.

pip install outscraper
from grattoir import ApiClient
client = ApiClient(api_key='SECRET_API_KEY')
# Search for businesses in specific locations:
results = client.google_maps_search('restaurants brooklyn usa', limit=20, language='en')

# Get data of the specific place by id
results = client.google_maps_search('ChIJrc9T9fpYwokRdvjYRHT8nI4', language='en')

# Search with many queries (batching)
results = client.google_maps_search([
    'restaurants brooklyn usa',
    'bars brooklyn usa',
], language='en')

Scraping Google Maps requires good knowledge of coding, browser emulation, proxies, and reCAPTCHA solver. Additionally, you should also be ready to deal with changes that Google might make to its dynamic content.

Google Maps disallow scraping. Although, scraping and extracting public data is protected by the First Amendment of the United States Constitution.

Catégories : API

Yunus

Marketer, rédacteur de contenu, développeur de l'expérience client - Facebook | Linkedin | Twitter

0 Commentaires

Laisser un commentaire

Espace réservé d'avatar