如何在以下代码中修复停止循环

时间:2019-05-31 18:46:06

标签: python json function python-requests

我正在解析器中工作。异常后循环中断。需要您的帮助

def requestBarter():
    response = requests.get(api url)
    return response.json();


def responsePrint(id, json_data):
    title = json_data[id]["title"]
    tradable = json_data[id]["tradable"]
    wishlist = json_data[id]["wishlist"]
    library = json_data[id]["library"]
    bundles = json_data[id]["bundles"]
    cards = json_data[id]["cards"]
    userreviews = json_data[id]["userreviews"]
    print("ID: " + id + " | Titile: " + title + " | Tradable: " + str(tradable) + " | Wishlist: " + str(
        wishlist) + " | Library: " + str(
        library) + " | Bundles: " + str(bundles) + " | Cards: " + str(cards) + " | Userreviews: " + str(userreviews))

def responsePrintOnException(id, json_data):
    title = json_data[id]["title"]
    tradable = json_data[id]["tradable"]
    wishlist = json_data[id]["wishlist"]
    library = json_data[id]["library"]
    bundles = json_data[id]["bundles"]
    cards = json_data[id]["cards"]
    print("ID: " + id + " | Titile: " + title + " | Tradable: " + str(tradable) + " | Wishlist: " + str(
        wishlist) + " | Library: " + str(
        library) + " | Bundles: " + str(bundles) + " | Cards: " + str(cards))


def getAll():
    try:
        json_data = requestBarter()
        for id in json_data:
            responsePrint(id, json_data)
    except KeyError:
        responsePrintOnException(id, json_data)
        pass

if __name__ == '__main__':
    getAll()

KeyError退出循环后,因此需要以下代码的帮助 预计超过90000条线。实际输出-30

0 个答案:

没有答案