使用python尝试使用github API进行身份验证和搜索存储库,结果很少



我正在尝试使用python和github API搜索使用javascript的存储库,并将链接到存储库中的文件。

import requests
from pprint import pprint
username = #my username here!
token = #my token here!
user_data = requests.get(f"https://api.github.com/search/repositories?q=language:js&sort=stars&order=desc", auth=(username,token)).json()
headers = {'Authorization': 'token ' + token}
login = requests.get('https://api.github.com/user', headers=headers)
print(login.json())
f = open("snapshotJS.txt", "w")
for userKeys in user_data.keys():
if userKeys == "items":
for item in user_data[userKeys]:
for lines in item:
if lines == "html_url":
print(item.get(lines))
f.write(item.get(lines) + "n")
f.close()

当我运行代码时,我每次只在我的文本文件中得到30个链接(授予,它们每次运行时都是不同的链接)。我怎么可能一次得到超过30个呢?既然我有一个个人令牌,我不应该能够收到多达5000个请求吗?

对不起,如果它是小的东西我错过了,我是新的API!

如果未指定页面大小,Github API将返回每个页面30个条目。

返回多个条目的请求将默认分页为30个条目。您可以使用page参数指定更多的页面。对于某些资源,还可以使用per_page参数将自定义页面大小设置为100。

要在一个页面中获取更多的记录,使用per_page查询参数。

要获取所有记录,使用while循环来获取页面,直到没有页面剩余。

最新更新