diff --git a/lib/routes/kpmg/insights.js b/lib/routes/kpmg/insights.js index 0337f8fa8c..0b46211a9e 100644 --- a/lib/routes/kpmg/insights.js +++ b/lib/routes/kpmg/insights.js @@ -1,54 +1,80 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const url = require('url'); -const host = 'https://home.kpmg'; module.exports = async (ctx) => { const link = 'https://home.kpmg/cn/zh/home/insights.html'; - const api = 'https://home.kpmg/search/?all_sites=false&site=cn_zh&language=zh&x1=KPMG_Tab_Type&q1=Insights&sort=KPMG_Filter_Date&facets=false'; const response = await got({ - method: 'get', - url: api, + method: 'post', + url: `https://home.kpmg/esearch/cn-zh`, headers: { Referer: link, }, + json: { + query: '', + filters: { + all: [ + { + kpmg_tab_type: ['Insights'], + }, + ], + }, + result_fields: { + kpmg_title: { + raw: {}, + }, + kpmg_article_date_time: { + raw: {}, + }, + kpmg_url: { + raw: {}, + }, + }, + page: { + size: 20, + current: 1, + }, + sort: { + kpmg_filter_date: 'desc', + }, + }, }); - const list = response.data['customer-results'].resultset.results.result; - const out = await Promise.all( - list.map(async (item) => { - const title = item.KPMG_Title; - const itemUrl = url.resolve(host, item.KPMG_URL); + const list = response.data.results.map((item) => ({ + title: item.kpmg_title.raw, + link: item.kpmg_url.raw, + pubDate: item.kpmg_article_date_time.raw, + })); - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } + const item = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const response = await got.get(item.link); + const $ = cheerio.load(response.data); - const response = await got.get(itemUrl); - const $ = cheerio.load(response.data); - let description = $('div.bodytext-data').html(); + if ($('a.component-link')) { + const link = $('a.component-link').attr('href'); + const size = $('a.component-link .downloadSize').text(); + $('a.component-link').replaceWith( + `
+
+ 点击下载 PDF ${size}
+