如何从 api 中获取特定数据?

How to get specific data from an api?

我正在尝试打印一件商品的最低价格。问题是当卖家列出新商品时 API 数据发生变化。例如,这是我的脚本和价格 api link: item linkapi link

import requests, json

params = {
    'game': 'csgo',
    'item': 'desert-eagle-light-rail-field-tested'
}

response = requests.get('https://integration.bynogame.com/api/listing/list/', params=params)

ads = json.loads(response.text)["response"]["data"]["ads"][5]
print("Fiyat:", ads["price"], "Stok:", ads["count"], "Satıcı Adı:", ads["sellerMarketName"], sep="  ")
ads = json.loads(response.text)["response"]["data"]["ads"][4]
print("Fiyat:", ads["price"], "Stok:", ads["count"], "Satıcı Adı:", ads["sellerMarketName"], sep="  ")
ads = json.loads(response.text)["response"]["data"]["ads"][3]
print("Fiyat:", ads["price"], "Stok:", ads["count"], "Satıcı Adı:", ads["sellerMarketName"], sep="  ")
ads = json.loads(response.text)["response"]["data"]["ads"][2]
print("Fiyat:", ads["price"], "Stok:", ads["count"], "Satıcı Adı:", ads["sellerMarketName"], sep="  ")
ads = json.loads(response.text)["response"]["data"]["ads"][1]
print("Fiyat:", ads["price"], "Stok:", ads["count"], "Satıcı Adı:", ads["sellerMarketName"], sep="  ")
ads = json.loads(response.text)["response"]["data"]["ads"][0]
print("Fiyat:", ads["price"], "Stok:", ads["count"], "Satıcı Adı:", ads["sellerMarketName"], sep="  ")

我不知道如何打印最低价。如果 response > data > ads number 匹配,我的打印所有列表。如果不是,输出如下所示:image link

你可以这样做:

ads = json.loads(response.text)["response"]["data"]['ads'] # grab all ads
lowest_price = ads[0]['price'] # use the first ad as the max price
for item in ads[1:]: # go through all ad items (besides first item)
    if item['price'] < lowest_price: # find the lowest price by comparing
        lowest_price = item['price'] # update lowest price if it beats previous low
print(lowest_price) # print out the final lowest price