如何使用GitHub API在GitHub中获取存储库的依存关系信息? [英] How to use GitHub API to get a repository's dependents information in GitHub?

查看:77
本文介绍了如何使用GitHub API在GitHub中获取存储库的依存关系信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用GitHub API v4获取一些信息时,我可以使用 repository.dependencyGraphManifests 轻松获得依赖关系.但是我找不到任何使用GitHub API v4来获取依赖项信息的方法,尽管我可以在 Insights-> Dependency Graph-> Dependents 中看到它.我想知道是否有任何可能的方法可以在GitHub存储库中获取受抚养人信息?无论是GitHub API还是其他东西.

When I was using GitHub API v4 to get some information, I can easily get dependencies by using repository.dependencyGraphManifests. But I can't find any way to use GitHub API v4 to get the dependents information, though I can see it in the Insights->Dependency Graph->Dependents. I want to know if there is any possible way to get the dependents information in a GitHub repository? Whether GitHub API or something else.

推荐答案

我认为您无法使用Github API(Rest或Graphql)获得依赖项项目,一种方法可能是使用如下所示的抓取方式脚本:

I don't think you can get the dependents project using Github API (Rest or Graphql), one way could be to use scraping like the following python script :

import requests
from bs4 import BeautifulSoup

repo = "expressjs/express"
page_num = 3
url = 'https://github.com/{}/network/dependents'.format(repo)

for i in range(page_num):
    print("GET " + url)
    r = requests.get(url)
    soup = BeautifulSoup(r.content, "html.parser")

    data = [
        "{}/{}".format(
            t.find('a', {"data-repository-hovercards-enabled":""}).text,
            t.find('a', {"data-hovercard-type":"repository"}).text
        )
        for t in soup.findAll("div", {"class": "Box-row"})
    ]

    print(data)
    print(len(data))
    paginationContainer = soup.find("div", {"class":"paginate-container"}).find('a')
    if paginationContainer:
        url = paginationContainer["href"]
    else:
        break

尝试此python脚本

这篇关于如何使用GitHub API在GitHub中获取存储库的依存关系信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆