赞
踩
Gradle
implementation("org.jsoup:jsoup:1.12.1")
Maven
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>
package org.napolun.easyapi.code import cn.hutool.core.util.StrUtil import org.jsoup.Jsoup /** * gitee * * @author chenxc * @email 997909544@qq.com * @Date 2019/11/25 11:40 */ object Gitee { private const val GITEE_HOST = "https://gitee.com/" private const val GITEE_REPO = GITEE_HOST + "explore/all?lang={}&order={}&page={}" /** * 获得gitee trending * * @param {String} language 语言 * @param {String} order recommend starred latest */ fun trending(language: String, order: String, page: Int): MutableCollection<TrendingResult> { var doc = Jsoup.connect(StrUtil.format(GITEE_REPO, language, order, page)).get() var list = doc.select(".explore-repo__list .item") var resultList: MutableCollection<TrendingResult> = mutableListOf() for (item in list) { var trendingResult = TrendingResult() var titleArr = item.select(".project-namespace-path").attr("title").split("/") var hrefArr = item.select(".project-namespace-path").attr("href").split("/") trendingResult.title = titleArr[1] trendingResult.description = item.select(".project-desc").text() trendingResult.url = GITEE_HOST + hrefArr[1] + "/" + hrefArr[2] trendingResult.coverUrl = item.select(".project-creator-link img").attr("src") trendingResult.author = titleArr[0] trendingResult.authorUrl = GITEE_HOST + hrefArr[1] var social = item.select(".explore-project__meta-social")[0].getElementsByTag("a") if (social.size == 2) { trendingResult.stars = social[1].getElementsByTag("span").text() } if (social.size == 3) { trendingResult.forks = social[2].getElementsByTag("span").text() } trendingResult.language = item.select(".project-meta")[0] .getElementsByTag("a")[0].text() trendingResult.updateTime = item.select(".timeago").text() trendingResult.readmeUrl = GITEE_HOST + hrefArr[1] + "/" + hrefArr[2] + "/raw/master/README.md"; resultList.add(trendingResult) } return resultList } }
参数:
language
: 可选, 语言, 默认全部order
: 可选, 排序, 默认 starred
, 全部: recommend
, starred
and latest
.page
: 必填, 页码返回值:
[ { "author":"程序猿DD", "authorUrl":"https://gitee.com/didispace", "coverUrl":"https://avatar.gitee.com/uploads/88/437188_didispace.png!avatar60?1548556333", "createTime":"", "description":"Spring Boot基础教程,Spring Boot 2.x版本连载中!!!", "forks":"4.9K", "language":"Java", "readmeUrl":"https://gitee.com/didispace/SpringBoot-Learning/raw/master/README.md", "stars":"", "title":"SpringBoot-Learning", "updateTime":"29天前", "url":"https://gitee.com/didispace/SpringBoot-Learning" } ]
上述代码,均已上传github,地址 https://github.com/chenxxcc/EasyAPI
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。