简体   繁体   English

如何从我的 json api 请求中取出这些特定信息?

[英]How do I take out this certain information from my json api request?

I'm pretty new to Python and I'd love to learn, don't know much and I've been trying to do some things with API.我是 Python 的新手,我很想学习,但我知道的不多,而且我一直在尝试用 API 做一些事情。 This is my code:这是我的代码:

import requests

response = requests.get("https://poe.ninja/api/data/itemhistory?league=Sanctum&type=Essence&itemId=373")
response2 = requests.get("https://www.pathofexile.com/api/trade/exchange/Sanctum")

print(response.status_code)
print(response2.status_code)

print(response.json())


The output is:输出是:

200
403
[{'count': 10, 'value': 10.870322580645162, 'daysAgo': 5}, {'count': 83, 'value': 8.737884615384615, 'daysAgo': 4}, {'count': 99, 'value': 8.0, 'daysAgo': 3}, {'count': 99, 'value': 8.0, 'daysAgo': 2}, {'count': 99, 'value': 
8.0, 'daysAgo': 1}, {'count': 99, 'value': 8.0, 'daysAgo': 0}]

The 200 from what i know stands for me being able to access the API, the 403 is the second request which I am forbidden to access.据我所知,200 代表我可以访问 API,403 是我被禁止访问的第二个请求。 I'd like to get the value of "8.0" from the last line that says 'daysAgo': 0我想从最后一行“daysAgo”中获取“8.0”的值:0

Found out an answer after minding this problem in my classes.在我的课堂上关注这个问题后找到了答案。 There's the answer for those wondering:对于那些想知道的人来说,答案是:

for entry in data:
    if entry['daysAgo'] == 0:
        print(entry['value'])
        break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM