这学期打算做一个关于 GitHub 的 Android 应用,其中一个模块就是查看 GitHub 当天,当周,当月的热门项目和开发者.其实 GitHub 给了开发者相当丰富的 API 接口 developer.github.com/v3/ ,包括认证,搜索,活动等接口,但就是没有提供获取 Trending 的接口.去 GitHub Trending 的主页看了一下,并看了其 html 代码,发现想要的东西都可以用爬虫爬去下来,于是就着手爬去信息.
以下所有请求都为 get 请求, 请求主地址为 https://trendings.herokuapp.com
获取热门项目
路径
/repo
参数
名称 类型 描述
lang 字符串 可选,热门项目的语言
since 字符串 可选,get 请求参数,无这参数则自动获取当天的热门项目,参数值只有三个,分别是 daily,weekly,monthly.
例如请求 https://trendings.herokuapp.com/repo?lang=java&since=weekly 返回结果:
获取热门开发者
//status code: 201
{
"count": 25,
"msg": "done",
//项目集合
"items": [
{
//项目贡献者的头像地址集合
"avatars": [
"https://avatars0.githubusercontent.com/u/16903644?v=3&s=40",
"https://avatars2.githubusercontent.com/u/8622362?v=3&s=40",
"https://avatars0.githubusercontent.com/u/10773353?v=3&s=40",
"https://avatars3.githubusercontent.com/u/6392550?v=3&s=40",
"https://avatars1.githubusercontent.com/u/3837836?v=3&s=40"
],
//项目的地址
"repo_link": "https://github.com/kdn251/interviews",
//项目描述
"desc": "Everything you need to know to get the job.",
//项目仓库
"repo": "kdn251/interviews",
//目前为止的的stars数
"stars": "5,772",
//目前为止的forks数
"forks": "539",
//项目所属语言
"lang": "Java",
//今天或者这周或者这个月的starts数
"added_stars": "4,591 stars this week"
},
.
.
.
]
}
路径
/developer
参数
名称 类型 描述
lang 字符串 可选,热门开发者使用的主要语言
since 字符串 可选,get 请求参数,无这参数则自动获取当天的热门开发者,参数值只有三个,分别是 daily,weekly,monthly.
请求 https://trendings.herokuapp.com/developer?lang=java&since=weekly 返回结果:
获取 GitHub 上的 trending 语言.
//status code: 201
{
"count": 25,
"msg": "done",
//开发者集合
"items": [
{
//开发者在GitHub上的用户名
"user": "google",
//开发者在GitHub上的主页链接
"user_link": "https://github.com/google",
//开发者的全名
"full_name": "(Google)",
// 开发者的头像地址
"developer_avatar": "https://avatars1.githubusercontent.com/u/1342004?v=3&s=96"
},
.
.
.
]
}
请求地址: https://trendings.herokuapp.com/lang 返回:
异常
//status code: 201
{
"count": 464,
"items": [
"1C-Enterprise",
"ABAP",
"ABNF",
"ActionScript",
"Ada",
.
.
.
"YANG",
"Zephir",
"Zimpl"
],
"msg": "suc"
}
有时候去访问 GitHub 的 trending 时, 会找不到热门项目或者开发者的, 这时就会返回如下的 json.:
维护
//status code: 404
{
"msg": "Unavialiable.",
"count": 0,
"items": []
}
若某个接口无法调用,请通过简信或者邮箱 doforce@126.com 与我取得联系,我会尽快修复问题.
GitHub 项目地址
来源: https://juejin.im/post/5a5c66026fb9a01cae0f9f4d