How to get data from all pages in Github API with Python?

前端 未结 6 2042
借酒劲吻你
借酒劲吻你 2021-02-05 17:55

I\'m trying to export a repo list and it always returns me information about the 1rst page. I could extend the number of items per page using URL+\"?per_page=100\" but it\'s not

6条回答
  •  野的像风
    2021-02-05 18:45

    import requests
    
    url = "https://api.github.com/XXXX?simple=yes&per_page=100&page=1"
    res=requests.get(url,headers={"Authorization": git_token})
    repos=res.json()
    while 'next' in res.links.keys():
      res=requests.get(res.links['next']['url'],headers={"Authorization": git_token})
      repos.extend(res.json())
    

    If you aren't making a full blown app use a "Personal Access Token"

    https://github.com/settings/tokens

提交回复
热议问题