I'm retrieving data from a API in python that randomize its result, but the entire result is paginated. What happens is that sometimes, the same element appears in different pages. So I end up getting one element several times, and others are missing.
I thought that using session would solve this, but it doesn't.
def get_result(data=data, headers=headers):
url = compose_url(page_number=1)
s = requests.Session()
response = s.get(url, headers=headers, data=json.dumps(data), verify=False)
resp = response.json()
total_pages = resp['total_pages']
all_info = []
for current_page_number in range(1, total_pages+1):
url = compose_url(page_number=current_page_number)
response = s.get(url, headers=headers, data=json.dumps(data), verify=False)
resp = response.json()
elements = resp['elements']
for element in elements:
all_info.append(do_something_with_element(element))
return all_info
Is there a way to make only one request that loads all data of the paginated result, so I don't have to request again the server (because it causes the API to randomize the response)?
source https://stackoverflow.com/questions/71019068/is-it-possible-to-load-all-data-of-a-paginated-api-with-only-one-requestpython
Comments
Post a Comment