有没有一种使用API​​在python中发出多个请求的方法?

时间:2020-04-29 20:23:37

标签: python api search get-request

我一直在尝试找出如何在python中发出多个请求(我正在使用food API)。到目前为止,我正在寻找不同的原料,但想进一步介绍一下我的食谱中的葡萄酒建议。我不确定是否可行,但到目前为止,这是我的代码:

import requests
from pprint import pprint

recipe_ingredients = input("What is the recipe ingredients? ")
number_recipes = input("How many recipes do you want? ")
url = 'https://api.spoonacular.com/recipes/findByIngredients?ingredients={}&number={}'.format(recipe_ingredients,number_recipes)

response = requests.get(url)
print(response)

recipes = response.json()
# pprint(recipes)

for recipe in recipes:
    print(recipe['usedIngredients'])
    if len(recipe['usedIngredients']) != 0:
        title = recipe['title']
        print(title)

        ingredients = recipe['usedIngredients']
        for ingredient in ingredients:
            print(ingredient['originalString'])
        # print(ingredients)

我考虑过在最后#print(成分)之后实现以下代码:

** paired_wine =输入(“您的主要成分是什么?”)

输出应为配方成分打印推荐的酒

url =('https://api.spoonacular.com/food/wine/pairing?food= {}') 响应= requests.get(URL) 打印(响应) wine = response.json()

pprint(葡萄酒)**

但是,一旦输入成分,控制台就会为我提供 的输出。谁能帮我解决这个问题,让我的输出是推荐的葡萄酒,因为我是python新手? API密钥不是问题,因为我以正确的格式在网址末尾输入了它。 预先感谢

0 个答案:

没有答案