我试图抓取一个地区的所有"药店/药房",但我只得到有限数量的而不是全部。
有没有办法一次获取所有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 最多返回 20 个结果:
地点 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')