【问题标题】:Google Maps API scraping ALL places in an areaGoogle Maps API 抓取区域内的所有地点
【发布时间】:2019-10-21 12:06:11
【问题描述】:

我正试图搜索一个区域内所有的“药店/药房”,但我只得到了有限的数量而不是全部。

有没有办法一次性获取所有的json数据?

url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
location = "33.589886, -7.603869"
radius = 26000
place_type = "pharmacy"
language = "fr"
r = requests.get(url + '&location=' +str(location)+'&radius='+str(radius) +   
'&type='+place_type+'&language='+language+'&key=' + api_key) 

我只得到其中的 20 个,而我想在那个半径范围内得到全部。

【问题讨论】:

  • 场所 API 被限制为最多 60 个响应(以 20 个为一组)

标签: python json google-maps


【解决方案1】:

根据documentation,Places API 最多返回 20 个结果:

Places API 每次查询最多返回 20 个建立结果

然后您应该使用next_page_token 生成一个新查询并获得下一页结果:

next_page_token 包含一个可用于返回最多 20 个附加结果的令牌。如果没有要显示的其他结果,则不会返回 next_page_token。可以返回的最大结果数为 60。在发出 next_page_token 和它变为有效之间存在短暂的延迟。

例子:

next_page_token = r.json().get('next_page_token')

while next_page_token:
    r = requests.get(url + '&pagetoken=' + next_page_token)

    # Parse the results page

    next_page_token = r.json().get('next_page_token')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 2012-11-23
    相关资源
    最近更新 更多