我使用API访问Github中所有基于Python的存储库的名称。但是,我的脚本只返回1020回购。当我查看github网站时,结果是>我在这里错过了一些东西吗?
def get_names(response):
content = json.loads(response.text)
return [it['full_name'] for it in content['items']]
query = dict(q="language:python",sort="stars",order="desc",per_page=100)
# Loop through results pages, get names
response = requests.get('https://api.github.com/search/repositories', params=query,headers=header)
names, idx = [], 0
while response.ok:
names.extend(get_names(response))
if 'next' in response.links.keys():
idx += 1
print('Getting page {0}'.format(idx))
print response.headers
response = requests.get(response.links['next']['url'],headers=header)
sleep(2)
else:
break
print "Total Github-Python Package:",len(names)
答案 0 :(得分:0)
正如您在documentation中找到的那样:
为满足这一需求,GitHub Search API最多可提供 1,000 每次搜索的结果。
所以这是一种预期的行为。你很幸运得到1020而不是1000:)