主页整改
This commit is contained in:
@@ -5,7 +5,6 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
@@ -263,48 +262,36 @@ public class SysHomeController {
|
||||
// @CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "web_news", isHash = true)
|
||||
// @CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24)
|
||||
public Result getNews() {
|
||||
// 定义要爬取的URL
|
||||
String domain = "https://gonghui.ypi.edu.cn";
|
||||
try {
|
||||
// 使用Jsoup连接到URL并获取页面内容
|
||||
Document doc = Jsoup.connect(domain).get();
|
||||
|
||||
JSONObject root = new JSONObject();
|
||||
|
||||
// 3. 基层风采(来自 .pic-list1)
|
||||
List<JSONObject> grassrootsArray = new ArrayList<>();
|
||||
Elements grassrootsItems = doc.select(".news #wp_news_w21 ul li");
|
||||
List<NutMap> items = new ArrayList<>();
|
||||
Elements grassrootsItems = doc.select(".news #wp_news_w21 ul li");
|
||||
for (Element item : grassrootsItems) {
|
||||
|
||||
Element aTitle = item.select("a").first();
|
||||
Element meta = item.select(".Article_PublishDate").first();
|
||||
if (aTitle == null || meta == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String title = aTitle.attr("title").trim();
|
||||
String url = aTitle.attr("href").trim();
|
||||
|
||||
Element meta = item.select(".Article_PublishDate").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();
|
||||
}*/
|
||||
|
||||
JSONObject node = new JSONObject();
|
||||
node.set("title", title);
|
||||
node.set("date", date);
|
||||
node.set("url", "https://gonghui.ypi.edu.cn/" + url);
|
||||
//node.set("summary", summary);
|
||||
//node.set("image", StrUtil.isNotBlank(imageUrl) ? (domain + imageUrl) : "");
|
||||
grassrootsArray.add(node);
|
||||
NutMap node = NutMap.NEW();
|
||||
node.setv("text", title);
|
||||
node.setv("time", date);
|
||||
node.setv("href", url.startsWith("http://") || url.startsWith("https://") ? url : domain + "/" + url);
|
||||
items.add(node);
|
||||
}
|
||||
root.set("grassroots", grassrootsArray);
|
||||
return Result.success(root);
|
||||
|
||||
NutMap section = NutMap.NEW();
|
||||
section.setv("label", "\u7efc\u5408\u65b0\u95fb");
|
||||
section.setv("value", items);
|
||||
List<NutMap> news = new ArrayList<>();
|
||||
news.add(section);
|
||||
return Result.success(news);
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
return Result.success();
|
||||
|
||||
Reference in New Issue
Block a user