Bea*_*rai 11 google-maps google-maps-api-3 web-scraping
对不起这个问题,我是新来的.
我有一个项目,我需要抓取谷歌地图找到一个地区的所有公司,我刚刚听说我们决定项目的时候,我做了一些研究,并发现大多数刮刮服务需要某个公司现场开始搜索,但我需要该领域的所有公司,有人可以解释我应该如何开始?
我在这个帖子中看到了:从Google搜索结果中抓取数据是否可以?
他们谈论IP我知道ISP会为某些地区分配公共IP地址,但我该如何使用它来刮掉?
另外我发现一篇文章说我必须在他们的网站上使用Google API:https: //developers.google.com/maps/web-services/ 我应该使用哪种API?
我正在使用Ubuntu系统,如果我需要安装任何东西,我应该使用Windows操作系统吗?
谢谢和亲切的问候
更新:
我从http://py-googlemaps.sourceforge.net/发现我可以使用这个python代码:
local = gmaps.local_search('cafe near'+ destination)print local ['responseData'] ['results'] [0] ['titleNoFormatting'] Vie De France Bakery&Cafe
如果我用"公司"或任何名称取代咖啡馆,我相信我会得到我正在寻找的信息吗?另外我想知道是否有人可以告诉我如何进入配置界面?
edd*_*yoc 13
上面的语言应该是你"不合法允许"刮,而不是"不能".你可以刮,不管它是否合法是另一回事.
您可以使用google-search-resultspackage 来抓取 Google 地图。
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']}""")
Run Code Online (Sandbox Code Playgroud)
JSON 响应
{
"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...
]
}
Run Code Online (Sandbox Code Playgroud)
输出
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
Run Code Online (Sandbox Code Playgroud)
披露:我在 SerpApi 工作。
ihi*_*imv -19
法律不允许您从 Google Maps API 中抓取数据。更好的做法是存储place_id任何位置的并检索它以供以后使用。
请参阅此 Google 地图使用条款
10.1.3 数据导出或复制的限制。
(a) 禁止未经授权复制、修改、创作衍生作品或展示内容。除非这些条款明确允许,否则您不得复制、翻译、修改或创建任何内容或其任何部分的衍生作品(包括创建或贡献数据库),或公开展示任何内容或其任何部分。例如,禁止以下行为: (i) 创建地图图块的服务器端修改;(ii) 将多个静态地图图像拼接在一起以显示大于地图 API 文档中允许的地图;(iii) 根据内容创建邮件列表或电话营销列表;(iv) 将内容导出、写入或保存到第三方的基于位置的平台或服务。
(b) 不预取、缓存或存储内容。您不得预取、缓存或存储任何内容,除非您可以存储:(i) 出于提高 Maps API 实现性能的目的而临时、安全地存储有限数量的内容不允许在服务之外使用内容的方式;(ii) 地图 API 文档特别允许您存储的任何内容标识符或密钥。例如,您不得使用内容创建“地点”或其他本地列表信息的独立数据库。
(c) 禁止大量下载或批量传送内容。您使用服务的方式不得让您或任何其他人访问大量下载或批量提供任何内容,包括但不限于数字纬度或经度坐标、图像、可见地图数据或地点数据(包括商业数据)。列表)。例如,您不得提供使用 Maps API 中包含的内容的批量地理编码服务。