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

问题描述 投票:5回答:1

如何获取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
python python-requests github-api
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.