[英]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頁面中 獲取所需的值(需要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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.