Files
RSSHub/lib/v2/gov/ccdi/index.js
T
Felix Hsu 64322895ec refactor: try to mimic the js cookie behavior and bypass the anti spider in ccdi.gov (#10890)
* try to minic the js cookie behavior and bypass the anti spider

* add more selector for diff article

* regex polished
2022-09-26 19:13:18 +08:00

19 lines
613 B
JavaScript

const { rootUrl, parseNewsList, parseArticle } = require('./utils');
module.exports = async (ctx) => {
const defaultPath = '/yaowenn/';
let pathname = ctx.path.replace(/(^\/ccdi|\/$)/g, '');
pathname = pathname === '' ? defaultPath : pathname.endsWith('/') ? pathname : pathname + '/';
const currentUrl = `${rootUrl}${pathname}`;
const { list, title } = await parseNewsList(currentUrl, '.list_news_dl li', ctx);
const items = await Promise.all(list.map((item) => parseArticle(item, ctx)));
ctx.state.data = {
title,
link: currentUrl,
item: items,
};
};