首页 > 解决方案 > 使用 Python 和 Github API 从 repo 收集数据

问题描述

我正在研究一个项目,该项目涉及 python 使用 GitHub API 来收集来自 repo ( https://github.com/的明星、贡献者、PR 和问题的数量并将其存储在 CSV 文件中。

我正在尝试使用 BeautifulSoup4,但 API 方法是一种更稳定的方法。下面是我的小片段。我不确定如何使用 github API(pygithub) 获取公司与非公司的某些贡献者提出的问题的信息(以检查外​​部贡献者)。

from github import Github
# using username and password
# or using an access token
g = Github("***************************")
for repo in g.get_user().get_repos():
    print(repo.name)

print("**********Get Current Repos**********")
user = g.get_user()
user.login
print(user.login)
repo = g.get_repo("<any-repo>/<any-repo>")
repo.name
print(repo.name)
print("********Get the Repo Topics**************")

repo = g.get_repo("<any-repo>/<any-repo>")
repo.get_topics()
print(repo.get_topics())

print("*****Get the Star Count*************")
repo = g.get_repo("<any-repo>/<any-repo>")
repo.stargazers_count
print(repo.stargazers_count)
print("********Get the Open Issues*********")
repo = g.get_repo("<any-repo>/<any-repo>")
open_issues = repo.get_issues(state='open')
for issue in open_issues:
    print(issue)

print("******Get the Branch Count*******")
repo = g.get_repo("<any-repo>/<any-repo>")
print(list(repo.get_branches()))

PS:我仍然是python noobie。

标签: pythonapigithubweb-scrapingpygithub

解决方案


推荐阅读