UNPKG

rsshub

Version:
69 lines (68 loc) 2.29 kB
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"; //#region lib/routes/cqu/sci.ts const route = { path: "/sci/:category", categories: ["university"], example: "/cqu/sci/xyxw", parameters: { category: "分类名" }, features: { requirePuppeteer: true, antiCrawler: true }, name: "数学与统计学院", maintainers: ["Hagb"], handler, description: `| 学院新闻 | 学院公告 | 学院活动 | 学术活动 | | -------- | -------- | -------- | -------- | | xyxw | xygg | xyhd | xshd1 |` }; async function handler(ctx) { const { category } = ctx.req.param(); const url = `https://sci.cqu.edu.cn/index/xwzx/${category}.htm`; const { page, destroy } = await getPlaywrightPage(url, { onBeforeLoad: async (page) => { await page.route("**/*", (route) => { ["document", "script"].includes(route.request().resourceType()) ? route.continue() : route.abort(); }); }, gotoConfig: { waitUntil: "networkidle" } }); let response, cookieString; try { await page.waitForSelector(".inner-list1 a[href*=\"/info/\"]", { state: "attached", timeout: 3e3 }); response = await page.content(); cookieString = (await page.context().cookies()).map((c) => `${c.name}=${c.value}`).join("; "); } finally { await destroy(); } const $ = load(response); const links = $(".inner-list1 a[href*=\"/info/\"]").toArray().map((item) => { const a = $(item); const $item = a.closest("li"); const dateText = $item.find("span.sspan").text() || $item.find("p.hd-p02").text().replace("时间:", ""); return { title: a.text(), link: new URL(a.attr("href"), url).href, pubDate: timezone(parseDate(dateText), 8) }; }); const items = await Promise.all(links.map((item) => cache_default.tryGet(item.link, async () => { item.description = load(await rofetch(item.link, { headers: { Cookie: cookieString } }))("div.v_news_content").html(); return item; }))); return { title: $("title").text(), link: url, item: items }; } //#endregion export { route };