diff --git a/docs/parameter.md b/docs/parameter.md index f083076884..0288126e17 100644 --- a/docs/parameter.md +++ b/docs/parameter.md @@ -22,7 +22,7 @@ filter 选出想要的内容 - filter_time: 过滤时间,仅支持数字,单位为秒。返回指定时间范围内的内容。如果条目没有输出`pubDate`或者格式不正确将不会被过滤 -举例 1: `https://rsshub.app/bilibili/fav/2267573/801952073?filter=编曲|摄影` +举例 1: `https://rsshub.app/bilibili/fav/2267573/801952073?filter=编曲|摄影` 举例 2: filterout 去掉不要的内容 diff --git a/lib/routes/jpmorganchase/research.js b/lib/routes/jpmorganchase/research.js index 02853de1c9..cfb1080e03 100644 --- a/lib/routes/jpmorganchase/research.js +++ b/lib/routes/jpmorganchase/research.js @@ -1,31 +1,52 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const dateParser = require('@/utils/dateParser'); + +const base = 'https://institute.jpmorganchase.com'; +const url = `${base}/institute/research`; + +const parseDetails = async (link, ctx) => { + const fullLink = `${base}${link}`; + return ctx.cache.tryGet(fullLink, async () => { + const response = await got({ + url: fullLink, + }); + const $ = cheerio.load(response.data); + const authors = []; + $('.author-name').each((i, elem) => { + authors.push($(elem).text()); + }); + + return { + category: $('.eyebrow').text(), + author: authors.filter((e) => e).join(', '), + title: $('title').text() + ' | ' + $('.copy-wrap p').text(), + description: $('.jpmc-wrapper').html(), + link: fullLink, + pubDate: dateParser($('.date-field').text(), 'MMMM YYYY'), + }; + }); +}; -const url = 'https://www.jpmorganchase.com'; module.exports = async (ctx) => { const response = await got({ method: 'get', - url: `${url}/corporate/institute/research.htm`, + url, }); const title = 'All Reports'; const $ = cheerio.load(response.data); - const items = $('.globalphilsect') - .map((index, item) => { - item = $(item); - return { - title: item.find('.chaseanalytics-track-link').text(), - link: `${url}${item.find('.chaseanalytics-track-link').attr('href')}`, - description: item.find('.lead-in + p').text(), - pubDate: item.find('.lead-in').text(), - }; + const items = $('.item a') + .map(async (i, item) => { + const link = item.attribs.href; + return parseDetails(link, ctx); }) .get(); ctx.state.data = { title: `${title} - JPMorgan Chase Institute`, link: url, description: `${title} - JPMorgan Chase Institute`, - item: items, + item: await Promise.all(items), }; };