rsshub
Version:
Make RSS Great Again!
102 lines (101 loc) • 2.99 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as timezone } from "./timezone-DE--ze1V.mjs";
import { t as getPlaywrightPage } from "./playwright-Dd_brOFk.mjs";
import { load } from "cheerio";
import iconv from "iconv-lite";
//#region lib/routes/csc/notice.ts
const baseUrl = "https://www.csc.edu.cn";
const typeMap = {
lxtz: {
name: "遴选通知",
url: "/chuguo/list/24"
},
xmzl: {
name: "综合项目专栏",
url: "/chuguo/list/26"
},
wtjd: {
name: "常见问题解答",
url: "/chuguo/list/27"
},
lqgg: {
name: "录取公告",
url: "/chuguo/list/28"
},
xwzx: {
name: "新闻资讯",
url: "/news"
},
xwgg: {
name: "新闻公告",
url: "/news/gonggao"
}
};
const route = {
path: "/notice/:type?",
categories: ["study"],
example: "/csc/notice/lxtz",
parameters: { type: {
description: "分类",
default: "lxtz",
options: Object.entries(typeMap).map(([value, { name }]) => ({
value,
label: name
}))
} },
features: {
requirePuppeteer: true,
antiCrawler: true
},
name: "通知",
maintainers: ["Derekmini", "markmingjie"],
handler,
url: "www.csc.edu.cn",
description: `| 遴选通知 | 综合项目专栏 | 常见问题解答 | 录取公告 | 新闻资讯 | 新闻公告 |
| -------- | ------------ | ------------ | -------- | -------- | -------- |
| lxtz | xmzl | wtjd | lqgg | xwzx | xwgg |`
};
async function handler(ctx) {
const { type = "lxtz" } = ctx.req.param();
const limit = Number(ctx.req.query("limit") ?? 10);
const link = baseUrl + typeMap[type].url;
const { page, destroy } = await getPlaywrightPage(link, {
onBeforeLoad: async (page) => {
await page.route("**/*", (route) => ["document", "script"].includes(route.request().resourceType()) ? route.continue() : route.abort());
},
gotoConfig: { waitUntil: "domcontentloaded" }
});
await page.waitForSelector(".list-a li");
const html = await page.content();
const cookies = await page.context().cookies();
await destroy();
const headers = { cookie: cookies.map((c) => `${c.name}=${c.value}`).join("; ") };
const $ = load(html);
const list = $(".list-a li").slice(0, limit).toArray().map((item) => {
const $item = $(item);
const a = $item.find("a");
return {
title: a.attr("title"),
link: new URL(a.attr("href"), baseUrl).href,
pubDate: timezone(parseDate($item.find("span").text()), 8)
};
});
const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const response = await rofetch(item.link, {
responseType: "arrayBuffer",
headers
});
item.description = load(iconv.decode(Buffer.from(response), "gbk"))(".contents").html();
return item;
})));
return {
title: `${$("title").text().split("-", 1)[0].trim()} - 国家留学网`,
link,
language: "zh-CN",
item: out
};
}
//#endregion
export { route };