公考雷达 RSS Feed - 最新资讯
/*
- @name: 公考雷达
- @desc: 获取https://www.gongkaoleida.com/area/2460-2461-0-2,3,59,78-0,125,126,128的最新资讯 */
module.exports = (ctx) => ({ // 命名此路由为gkld route: 'gkld', // 定义此路由的请求链接为指定网址 feed: 'https://www.gongkaoleida.com/area/2460-2461-0-2,3,59,78-0,125,126,128', // 使用 cheerio 对请求返回的 HTML 进行解析 // 获取想要的信息 // 并将其格式化为 RSS // 最后返回格式化后的结果 // 这里使用了高阶函数,对 cheerio 操作进行了封装 // 可以直接调用 $ 对象进行解析 // 不需要再次传入 HTML // 详见 https://docs.rsshub.app/advanced.html#%E6%8F%90%E4%BE%9B%E5%8A%A8%E6%80%81%E6%8F%92%E5%85%A5 // 如果不理解这段代码,可以先去学习 JS 中的高阶函数和闭包 // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Closures // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/map // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/filter // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/replace // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp // https://cheerio.js.org/ async fetch() { const res = await ctx.cache.tryGet(this.feed, async () => await ctx.curl(this.feed)); const $ = res.data; const list = $('.content-list .item') .map((_, item) => { item = $(item); return { title: item.find('.title a').text(), link: item.find('.title a').attr('href'), pubDate: new Date(item.find('.date').text()).toUTCString(), author: item.find('.source').text(), description: item.find('.summary').text(), }; }) .get(); return { title: '公考雷达', link: this.feed, description: '获取https://www.gongkaoleida.com/area/2460-2461-0-2,3,59,78-0,125,126,128的最新资讯', item: list, }; }, });
原文地址: https://www.cveoy.top/t/topic/m04d 著作权归作者所有。请勿转载和采集!