Category: requests

Problem

Fetch all pages from a paginated API.

Solution

  while url:
    data = session.get(url).json()
    items.extend(data['results'])
    url = data.get('next')
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path