This commit is contained in:
=
2026-03-04 16:39:38 +08:00
parent 78e9c46a3d
commit 160b2ab945
@@ -298,7 +298,7 @@ public class SysHomeController {
// @CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24)
public Result getNews() {
// 定义要爬取的URL
String domain = "https://www.jshvc.edu.cn/gh/main.psp";
String domain = "https://gh.squ.edu.cn/";
try {
// 使用Jsoup连接到URL并获取页面内容
Document doc = Jsoup.connect(domain).get();
@@ -306,36 +306,30 @@ public class SysHomeController {
JSONObject root = new JSONObject();
// 3. 基层风采(来自 .pic-list1)
Elements grassrootsItems = doc.select("div.vsb-space.fiveRight[columns='1'] li");
List<JSONObject> grassrootsArray = new ArrayList<>();
Elements grassrootsItems = doc.select(".post-18 .news_list li");
int count = 0;
for (Element item : grassrootsItems) {
if (count >= 8) {break;}
Element aTitle = item.select(".news_title a").first();
String title = aTitle.text().trim();
Element aTitle = item.select("a").first();
if (aTitle == null) continue;
String title = aTitle.attr("title").trim();
String url = aTitle.attr("href").trim();
Element meta = item.select(".news_meta").first();
String date = meta.text().trim();
/*Element link = item.select(".nr").first();
String date = link.select(".date").text().trim();
String title = link.select(".news_title a").text().trim();
String url = link.select(".news_title a").attr("href").trim();
String summary = link.select(".news_text a").text().trim();
String imageUrl = "";
Element img = link.select(".news_imgs").first();
if (img != null) {
imageUrl = img.attr("src").trim();
}*/
// 提取日期
Element dateSpan = aTitle.selectFirst("span");
String date = (dateSpan != null) ? dateSpan.text().trim() : "";
JSONObject node = new JSONObject();
node.set("title", title);
node.set("date", date);
node.set("url", domain + url);
//node.set("summary", summary);
//node.set("image", StrUtil.isNotBlank(imageUrl) ? (domain + imageUrl) : "");
node.set("url", domain + (url.startsWith("/") ? "" : "/") + url);
grassrootsArray.add(node);
count++;
}
root.set("grassroots", grassrootsArray);
return Result.success(root);