Google Maps API抓取区域中的所有地方

时间:2019-10-21 12:06:11

标签: python json google-maps

我试图刮擦某个地区的所有“药店/药房”,但我只能得到的数量有限,而不是全部。

反正有一次一次获取所有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个,而我想在那个半径范围内完整地获取它们。

1 个答案:

答案 0 :(得分: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')