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. 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. I'd like to get the value of "8.0" from the last line that says 'daysAgo': 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.