python - 如何获取 GitHub 存储库的贡献者总数?
问题描述
如何获取 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 库)中抓取所需的值:
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
推荐阅读
- jmeter-3.2 - 尽管有公司防火墙,如何将您的手机连接到 JMeter 以记录脚本
- java - 如何修复 Android Studio 中的空指针异常?
- android - 使用我的自定义 android 应用程序打开谷歌地图后如何修复应用程序终止
- ios - 如何存储(在变量中)从 Xcode 中的数据库读取的 Firestore 文档数据
- regex - 正则表达式过滤掉特定字符串后面的特征
- neo4j - 如何计算具有特定条件的密码标签?
- java - 从 JSpinner 获取毫秒数
- c++ - 野兽 async_read() 是如何工作的?有什么选择吗?
- python - Kivy:添加屏幕后我的标签文本没有更新
- mysql - 如何使用带有正则表达式的 mysql 将表中的选择名称替换为 t 和 t.name 像 A 和 t.name 像 B 和 t.name 像 c