UNPKG

rsshub

Version:
45 lines (44 loc) 1.59 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.mjs"; import { load } from "cheerio"; //#region lib/routes/tongshang/index.ts const route = { path: "/", categories: ["other"], example: "/tongshang", name: "通商", maintainers: ["snipersteve"], handler }; async function handler() { const url = "https://www.tongshang.com/article/research/"; const oriUrl = "https://www.tongshang.com"; const match = (await rofetch(`${oriUrl}/TemResolve/?TemPresolveId=32&classid=30&ObjI=0&publicvar=1&charset=UTF-8`, { responseType: "text" })).match(/document\.write\((".*")\);/s); if (!match) throw new Error("Unable to extract the article list from the template response"); const $ = load(JSON.parse(match[1].replaceAll(/[\r\n\t]/g, " "))); const list = $("li").toArray(); return { title: "通商研究 - 通商律师事务所", link: url, item: await Promise.all(list.map((item) => { const $item = $(item); const subUrl = $item.find("a").attr("href"); const itemUrl = oriUrl + subUrl; const pubDate = timezone(parseDate($item.find(".font_ts").text()), 8); return cache_default.tryGet(itemUrl, async () => { const response = await rofetch(itemUrl); const $d = load(response); return { title: $d(".lm_newsCont_part1 .txt").text(), link: itemUrl, pubDate, description: $d(".lm_newsCont_part2 .left").html() }; }); })) }; } //#endregion export { route };