如何python如何处理从前端获取的数据,如何使用Python从Github API中的所有页面获取数据?...

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

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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值