如何获取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
关于python - 如何获取 GitHub 仓库的贡献者总数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53431480/