UNPKG

rsshub

Version:
75 lines (73 loc) 2.68 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { t as Language } from "./constants-CvBdW0m_.mjs"; import { load } from "cheerio"; //#region lib/routes/sicau/jiaowu.ts const $get = async (url, encoding = "gb2312") => new TextDecoder(encoding).decode(await ofetch_default(url, { responseType: "arrayBuffer" })); const $trim = (str) => { let s = str.trim(); s = s.startsWith("&nbsp;&nbsp;") ? s.slice(12) : s; s = s.endsWith("<br>") ? s.slice(0, Math.max(0, s.length - 4)) : s; return s.trim(); }; const route = { path: "/jiaowu/jxtz/:detail?", categories: ["university"], example: "/sicau/jiaowu/jxtz/detail", parameters: { detail: "是否抓取全文,该值只要不为空就抓取全文返回,否则只返回标题" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["jiaowu.sicau.edu.cn/web/web/web/index.asp"], target: "/jiaowu/jxtz" }], name: "教务处", maintainers: ["hualiong"], description: ` ::: tip 抓取全文返回会导致更长的响应时间,可以尝试使用 \`/sicau/jiaowu/jxtz\` 路径,这将只返回标题,然后再在应用内抓取全文内容。 ::: `, url: "jiaowu.sicau.edu.cn/", handler: async (ctx) => { const baseUrl = "https://jiaowu.sicau.edu.cn/web/web/web"; const { detail = null } = ctx.req.param(); const $ = load(await $get(`${baseUrl}/gwmore.asp`)); let items = $("tbody > .text-c:nth-child(-n+10)").toArray().map((item) => { const children = $(item).children(); const a = children.eq(2).find("a"); return { category: [children.eq(1).text()], link: `${baseUrl}/${a.attr("href")}`, title: a.children().first().text(), pubDate: timezone(parseDate(children.eq(3).text(), "YYYY-M-D"), 8), author: children.eq(4).text(), description: "请在应用内抓取全文内容" }; }); if (detail) items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { item.description = $trim(load(await $get(item.link))(".text1[width=\"95%\"] b").html()); return item; }))); return { title: "教学通知 - 四川农业大学教务处", link: "https://jiaowu.sicau.edu.cn/web/web/web/gwmore.asp", language: Language.Chinese, item: items }; } }; //#endregion export { route };