我从Google Places API发出一个查询“巴西酒店”的请求,代码如下:
# url variable store url
url = "https://maps.googleapis.com/maps/api/place/textsearch/json?"
# The text string on which to search
query = input('Search query: ')
# get method of requests module
# return response object
r = requests.get(url + 'query=' + query +
'&key=' + api_key +
'&maxResults=1000')
# json method of response object convert
x = r.json()
# store the value of result key in variable y
y = x['results']
#Getting information from other pages with "next_page_token" param
places=[]
params = {
'query': query,
'key' : api_key,
'maxResults': '1000'
}
while "next_page_token" in x:
params['pageToken'] = x['next_page_token'],
res = requests.get(url, params = params)
z = json.loads(res.content)
places.extend(z['results'])
print(places)
但是返回结果需要很长时间(超过1天)。所以我停止了执行,当我打印它时,我得到了许多重复的名字,例如,我得到了16K个位置,但只有26个唯一的位置
是否可以从Google Places API返回唯一值
目前没有回答
相关问题 更多 >
编程相关推荐