如何使用Python从Github API中的所有页面获取数据?

问题描述:

我正在尝试导出一个回购列表,它总是向我返回有关第一页的信息.我可以使用URL +?per_page = 100"扩展每页的项目数,但这不足以获取整个列表. 我需要知道如何获取从1、2,...,N页提取数据的列表. 我正在使用请求"模块,如下所示:

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 enough to get the whole list. I need to know how can I get the list extracting data from page 1, 2,...,N. I'm using Requests module, like this:

while i <= 2:
      r = requests.get('https://api.github.com/orgs/xxxxxxx/repos?page{0}&per_page=100'.format(i), auth=('My_user', 'My_passwd'))
      repo = r.json()
      j = 0
      while j < len(repo):
            print repo[j][u'full_name']
            j = j+1
      i = i + 1

在条件为因为我知道有2页,并且尝试以这种方式增加它,但它不起作用

I use that while condition 'cause I know there are 2 pages, and I try to increase it in that waym but It doesn't work

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