目录

Google Maps Scraping In Pure Python​

刮取谷歌地图需要良好的编码知识、浏览器模拟、代理和 reCAPTCHA解算器。 此外,你也应该准备好应对谷歌可能对其动态内容做出的改变。

First of all, you will need to mimic the real user’s behavior by using browser emulation. Using 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 代理人. 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解算器。

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: 如何用Python和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.它提供了方便的通道。 Outscraper API from applications written in the Python language which allows you to use Outscraper的服务 从你的代码中。

你可以先安装 该包裹 并在以下网站创建一个账户 外层.

Google Maps Scraping in Python

安装

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

				
					pip install outscraper
				
			

初始化

通过导入类和添加你的秘密API密钥来初始化Outscraper客户端。你可以在以下网站上生成API密钥 个人资料页面.

				
					from outscraper import ApiClient

client = ApiClient(api_key='SECRET_API_KEY')
				
			

使用实例

以下是如何通过使用搜索查询从谷歌地图上搜刮地方的例子。

				
					# Search for businesses in specific locations:
results = client.google_maps_search_v2(['restaurants brooklyn usa'], limit=20, language='en', region='us')

# Scrap Places by Two Queries
results = client.google_maps_search_v2(
    ['restaurants brooklyn usa', 'bars brooklyn usa'],
    limit=50, # limit of palces per each query
    language='en',
    region='US',
)

# Iterate over the results
for query_places in results:
    for place in query_places:
        print('query:', place['query'])
        print('name:', place['name'])
        print('phone:', place['phone'])
        print('website:', place['site'])
				
			

也可以通过使用地点标识来提取数据。

				
					# 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'])
				
			

现在就试试Outscraper SDK

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.

常问问题

最常见的问题和答案

你可以通过使用Outscraper SDK刮取谷歌地图结果。指定搜索查询、语言和其他参数,并发送您的请求。

pip install outscraper
from 外层 import ApiClient
client = ApiClient(api_key='SECRET_API_KEY')
# 搜索特定地点的企业。
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')

刮取谷歌地图需要良好的编码知识、浏览器模拟、代理和 reCAPTCHA解算器。 此外,你也应该准备好应对谷歌可能对其动态内容做出的改变。

谷歌地图不允许搜刮。虽然,搜刮和提取公共数据是受美国宪法第一修正案保护的。


尤努斯

市场营销人员、内容写作人员、客户体验开发人员----。 Facebook | 领英 | 推特

0 评论

发表评论

头像占位符