如何获取 GitHub 存储库的贡献者总数?

How to get the total amount of contributors to a GitHub repository?

如何获取 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

作为最后的手段,您可以从 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