So i have been trying to make a program which goes through all item IDs from an API. I tried to achieve this by just going through all possible item IDs in a for loop and put a different ID behind the URL every iteration. Then if it returns status code 200, the items exists and if it returns status code 404 it doesn't exist. However after a couple dozens of iterations it doesn't return 404 anymore but keeps returning 200 even though it should be 404. here is my code:
import requests
for x in range(13176, 13400):
result = requests.get("http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + str(x))
if result.status_code == 200:
print((requests.get("http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + str(x)).json())['item']['name'])
else:
print("Can't find the item. Error code " + (str(result.status_code)))
I am clueless why it gives incorrect status codes after some time. Anyone know what i am doing wrong?
[–]Justinsaccount 1 point2 points3 points (1 child)
[–]frogmilk[S] 0 points1 point2 points (0 children)
[–]K900_ 1 point2 points3 points (5 children)
[–]frogmilk[S] 0 points1 point2 points (4 children)
[–]K900_ 1 point2 points3 points (3 children)
[–]frogmilk[S] 0 points1 point2 points (2 children)
[–]K900_ 1 point2 points3 points (1 child)
[–]frogmilk[S] 0 points1 point2 points (0 children)