rsshub
Version:
Make RSS Great Again!
64 lines (63 loc) • 2.11 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";
//#region lib/routes/cqu/net.ts
const route = {
path: "/net/:category",
categories: ["university"],
example: "/cqu/net/tzgg",
parameters: { category: "分类名" },
features: {
requirePuppeteer: true,
antiCrawler: true
},
name: "信息化办公室",
maintainers: ["Hagb"],
handler,
description: `| 通知公告 | 单位动态 | 语言文字 |
| -------- | -------- | -------- |
| tzgg | dwdt | yywz |`
};
async function handler(ctx) {
const { category } = ctx.req.param();
const url = `https://net.cqu.edu.cn/index/${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("li[id] p.detail", { 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 = $("li[id] > a").toArray().map((item) => {
const $item = $(item);
return {
title: $item.find("p.detail").text(),
link: new URL($item.attr("href"), url).href,
pubDate: timezone(parseDate($item.find("p.time").text(), "YYYY年MM月DD日"), 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 };