如何获取GitHub存储库的总贡献者?由于分页,API使其变得相当困难。
这是我到目前为止使用Python尝试过的:
contributors = "https://api.github.com/repos/JetBrains/kotlin-web-site/contributors"
x = requests.get(contributors)
y = json.loads(x.text)
len(y) # maximum 30 because of pagination
答案 0 :(得分:1)
万不得已的话,您可以从GitHub HTML page(需要lxml.html lib)中抓取所需的值:
import requests
from lxml import html
r = requests.get('https://github.com/JetBrains/kotlin-web-site')
xpath = '//span[contains(@class, "num") and following-sibling::text()[normalize-space()="contributors"]]/text()'
contributors_number = int(html.fromstring(r.text).xpath(xpath)[0].strip())
print(contributors_number)
# 338