Answer the question
In order to leave comments, you need to log in
How to make pagination (iterator) through API pages?
There is an API that only returns 100 results per page. I'm trying to make a while loop so that it goes through all the pages and takes the results from all the pages, but it doesn't work. I would be grateful if you could help me figure it out.
The code:
params = dict(
order_by='salary_desc',
text=keyword,
area=area,
period=30, # days
per_page=100,
page = 0,
no_magic='false', # disable magic
search_field='name' # available: name, description, company_name
)
response = requests.get(
BASE_URL + '/vacancies',
headers={'User-Agent': generate_user_agent()},
params=params,
)
response
items = response.json()['items']
vacancies = []
for item in items:
vacancies.append(dict(
id=item['id'],
name=item['name'],
salary_from=item['salary']['from'] if item['salary'] else None,
salary_to=item['salary']['to'] if item['salary'] else None,
currency = item['salary']['currency'] if item['salary'] else None,
created=item['published_at'],
company=item['employer']['name'],
area = item['area']['name'],
url=item['alternate_url']
))
while vacancies == True:
params['page'] += 1
Answer the question
In order to leave comments, you need to log in
well, the request to the api also needs to be done in a cycle, and not just increase the page
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question