rsshub
Version:
Make RSS Great Again!
76 lines (75 loc) • 2.26 kB
JavaScript
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs";
import { t as cache_default } from "./cache-C1Y-9qDV.mjs";
import { t as got_default } from "./got-DUpa1V3-.mjs";
import { t as timezone } from "./timezone-UiMFOuvL.mjs";
import { load } from "cheerio";
//#region lib/routes/bupt/scss.ts
const route = {
path: "/scss/tzgg",
categories: ["university"],
example: "/bupt/scss/tzgg",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["scss.bupt.edu.cn/index/tzgg1.htm"],
target: "/scss/tzgg"
}],
name: "网络空间安全学院 - 通知公告",
maintainers: ["ziri2004"],
handler,
url: "scss.bupt.edu.cn"
};
async function handler() {
const rootUrl = "https://scss.bupt.edu.cn";
const currentUrl = `${rootUrl}/index/tzgg1.htm`;
const pageTitle = "通知公告";
const selector = ".Newslist li";
const response = await got_default({
method: "get",
url: currentUrl
});
const $ = load(response.data);
const list = $(selector).toArray().map((item) => {
const $item = $(item);
const $link = $item.find("a");
if ($link.length === 0 || !$link.attr("href")) return null;
const link = new URL($link.attr("href"), rootUrl).href;
const rawDate = $item.find("span").text().replace("发布时间:", "").trim();
return {
title: $link.text().trim(),
link,
pubDateRaw: rawDate
};
}).filter((item) => item !== null);
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await got_default({
method: "get",
url: item.link
});
const content = load(detailResponse.data);
const newsContent = content(".v_news_content");
newsContent.find("p, span, strong").each((_, el) => {
const element = content(el);
const text = element.text().trim();
if (text === "") element.remove();
else element.replaceWith(text);
});
item.description = newsContent.text();
item.pubDate = timezone(parseDate(item.pubDateRaw), 8);
return item;
})));
return {
title: `北京邮电大学网络空间安全学院 - ${pageTitle}`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };