gpt4 book ai didi

python - 从 Python 脚本查询远程 API

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:21 25 4
gpt4 key购买 nike

我想将 Zomato 的评论 API 集成到我的 Python 脚本中。

我了解Python的基本编程,但至于API集成,我想知道

  • 如何继续使用 API
  • 应采取哪些步骤从 Python 查询 API
  • 如何将结果集成到我的脚本中

有哪些可行的选择?

最佳答案

您可以开始使用 Python 的 requests 模块。

获取类别列表的简单示例:

import requests

domain = "https://developers.zomato.com/api/v2.1"
headers = {'user-key': 'your_api_key_here'}

response = requests.get("{}/categories".format(domain), headers=headers).json()

for category in response["categories"]:
print(category)

这将输出如下内容:

{"categories": {"id": 1, "name": "Delivery"}}
{"categories": {"id": 2, "name": "Dine-out"}}
{"categories": {"id": 3, "name": "Nightlife"}}
{"categories": {"id": 4, "name": "Catching-up"}}
{"categories": {"id": 5, "name": "Takeaway"}}
# etc...

请求的文档 can be found here.

关于python - 从 Python 脚本查询远程 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36754110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com