The Iteration Loop Is Not Working Properly For API
There is an API that only produces one hundred results per page. I am trying to make a while loop so that it goes through all pages and takes results from all pages, but it does no
Solution 1:
You are incrementing the page prior to grabbing the response. Just reorder like so.
while True:
response = requests.get(BASE_URL + '/vacancies', headers={'User-Agent': generate_user_agent()}, params=params,)
items = response.json()['items']
if not items:
break
pages.append(items) # Do it for each page
params["page"] += 1
Post a Comment for "The Iteration Loop Is Not Working Properly For API"