Eze*_*ick 8

Andre的答案指出您在正确的位置引用API.由于您的问题是特定于python的,因此请允许我向您展示在python中构建提交的搜索URL的基本方法.在您注册Google的免费API密钥后的几分钟内,此示例将帮助您一路搜索内容.

ACCESS_TOKEN = <Get one of these following the directions on the places page>

import urllib

def build_URL(search_text='',types_text=''):
    base_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'     # Can change json to xml to change output type
    key_string = '?key='+ACCESS_TOKEN                                           # First think after the base_url starts with ? instead of &
    query_string = '&query='+urllib.quote(search_text)
    sensor_string = '&sensor=false'                                             # Presumably you are not getting location from device GPS
    type_string = ''
    if types_text!='':
        type_string = '&types='+urllib.quote(types_text)                        # More on types: https://developers.google.com/places/documentation/supported_types
    url = base_url+key_string+query_string+sensor_string+type_string
    return url

print(build_URL(search_text='Your search string here'))
Run Code Online (Sandbox Code Playgroud)

此代码将构建并打印一个URL,搜索您在最后一行中放置的任何内容,替换"您的搜索字符串".您需要为每次搜索构建其中一个URL.在这种情况下,我打印了它,以便您可以将其复制并粘贴到浏览器地址栏中,这将使您返回(在浏览器中)JSON文本对象,就像您的程序提交该URL时一样.我建议使用python 请求库在你的程序中获取它,你可以简单地通过获取返回的URL并执行此操作:

response = requests.get(url)
Run Code Online (Sandbox Code Playgroud)

接下来你需要解析返回的响应JSON,你可以通过使用json库转换它来做(例如查找json.loads).通过json.loads运行该响应后,您将获得一个包含所有结果的精美python字典.您还可以将该返回(例如,从浏览器或保存的文件)粘贴到在线JSON查看器中,以便在编写代码以访问json.loads中出现的字典时理解结构.

如果部分内容不明确,请随时发布更多问题.