I'm using an Indeed API from Rapid API to collect job data. The code snippet provided only returns results for 1 page. I was wondering how to set up a for loop to iterate through multiple pages and append the results together.
url = "https://indeed11.p.rapidapi.com/"
payload = {
"search_terms": "data visualization",
"location": "New York City, NY",
"page": 1,
"fetch_full_text": "yes"
}
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "{api key here}", # insert here,
"X-RapidAPI-Host": "indeed11.p.rapidapi.com"
}
response = requests.request("POST", url, json=payload, headers=headers)
As seen in the code above, the key "page" is set to a value of 1. How would I parameterize this value, and how would I construct the for loop while appending the results from each page?
"page": 1you would replace the1with a variable name, so you could trivially get that from incrementing a number in the loop. Then the other part you will need is to detect (by looking at the response content) when there is no longer a 'next' page of results, so you can break out of the loop. Other than that it's just a case of appending the results to a list each time through the loop.