每次函数通过 for 循环时增加一个值

Increasing a value each time a function passes through a for loop

我正在尝试从 API 创建一个 returns response.json[i] 的 for 循环,每次循环时 i 增加 1。

示例:

import requests
import json 

def get_url():
    url = "https://bing-news-search1.p.rapidapi.com/news/search"    

    querystring = {"q":"bitcoin","count":"20","textFormat":"Raw","safeSearch":"Off"}        

    headers = {
        'x-bingapis-sdk': "true",
        'x-rapidapi-host': "bing-news-search1.p.rapidapi.com",
        'x-rapidapi-key': "api_key"
        }       

    response = requests.request("GET", url, headers=headers, params=querystring)    
    print(response.json()["value"][i]["url"]) # Here is where I need i to increase each time
for i in range(10):
    get_url()

我的目标是 get_url() 到 运行 10 次,每次打印与增加的 i 值相关联的响应。抱歉,如果措辞不当,我是一个完全的初学者,并且 100% 自学成才。提前致谢!

添加 i 作为 get_url 的参数:

def get_url(i):

然后将其添加到 for 循环中的 get_url 调用中:

for i in range(10):
    get_url(i)