rsshub
Version:
Make RSS Great Again!
55 lines (54 loc) • 2.32 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 { load } from "cheerio";
//#region lib/routes/gov/mohrss/sbjm.ts
const route = {
path: "/sbjm/:category?",
categories: ["government"],
example: "/gov/mohrss/sbjm",
parameters: { category: "分类,见下表" },
name: "社保减免",
maintainers: ["nczitzk"],
description: `| 要点新闻 | 政策文件 | 工作动态 | 媒体报道 | 图片新闻 |
| -------- | -------- | -------- | -------- | -------- |
| ydxw | zcwj | gzdt | mtbd | tpxw |`,
handler
};
const rootUrl = "https://www.mohrss.gov.cn";
const challengePattern = /(?:WTKkN|bOYDu|wyeCN)['"]?:\s*\d+/g;
async function fetchWithAntiBot(url, cookie = "") {
const response = await rofetch(url, { headers: { cookie } });
const matches = response.match?.(challengePattern);
if (matches && !cookie) return fetchWithAntiBot(url, `__tst_status=${matches.slice(0, 3).reduce((sum, str) => sum + Number(/\d+/.exec(str)[0]), 0)}#;`);
return response;
}
async function handler(ctx) {
const { category = "ydxw" } = ctx.req.param();
const currentUrl = `${rootUrl}/SYrlzyhshbzb/rdzt/jfjf/${category}/`;
const $ = load(await fetchWithAntiBot(currentUrl));
const list = $("div[class^='rsb_jfjf_cont'] ul li").slice(0, 15).toArray().map((item) => {
const $item = $(item);
const a = $item.find("a");
return {
title: a.text().trim(),
link: new URL(a.attr("href"), currentUrl).href.replace(/^http:(?=\/\/www\.mohrss\.gov\.cn\/)/, "https:"),
pubDate: timezone(parseDate($item.find("span").text()), 8)
};
});
const items = await Promise.all(list.map((item) => item.link.startsWith(`${rootUrl}/`) ? cache_default.tryGet(item.link, async () => {
const content = load(await fetchWithAntiBot(item.link));
item.description = content("#insMainConTxt").html() || content(".TRS_Editor").html() || content(".art_p").html();
const pubDate = content("meta[name=\"PubDate\"]").attr("content");
if (pubDate) item.pubDate = timezone(parseDate(pubDate), 8);
return item;
}) : item));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };