循环似乎正在跳过网址

问题描述

我有一个完整的RIOT API网址列表。出于某种奇怪的原因,它似乎跳过了许多网址(其中20个),只打印了3个不同的网址。我做了print(url),它显示了所有的URL。 可能发生的情况是,它会通过防暴API中的每个游戏网址,并显示每个游戏的死亡人数(共20个)。相反,它发布了3个游戏死亡消息

 for urls in game_list:

            response=requests.get(urls)
            Loop=0
            
            while Loop<=10:
                index=0
                if response.json()['participantIdentities'][index]['player']['summonerName']!=sumName:
                    Loop= Loop+1
                    index=index+1
                elif response.json()['participantIdentities'][index]['player']['summonerName']==sumName:

                    deaths.append(response.json()['participants'][index]['stats']['deaths'])
                    kills.append(response.json()['participants'][index]['stats']['kills'])
                    assists.append(response.json()['participants'][index]['stats']['assists'])
                    visions.append(response.json()['participants'][index]['stats']['visionscore'])
                    csTotal.append(response.json()['participants'][index]['stats']['totalMinionsKilled'])
                    print(deaths)
                    break

解决方法

您应该将所有内容放入Try / Except的while循环中,并在“ Except”下放入Break。这是因为没有其他要循环的东西。 另一种方法是进行for循环,并遍历partnerIdentities中的所有内容。