From 6041624252dbf9cba198b1504518c722d99af11c Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 13 Oct 2020 18:28:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=9B=BD=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E7=A7=91=E6=8A=80=E7=9F=A5=E8=AF=86=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E4=BA=A7=E4=B8=9A=E6=94=BF=E7=AD=96=20(#5864)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 4 ++++ lib/router.js | 1 + lib/routes/cktest/policy.js | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/routes/cktest/policy.js diff --git a/docs/other.md b/docs/other.md index 2eace247d8..c4820a18ad 100644 --- a/docs/other.md +++ b/docs/other.md @@ -825,6 +825,10 @@ type 为 all 时,category 参数不支持 cost 和 free +### 产业政策 + + + ## 中国银行 ### 中国银行外汇牌价 diff --git a/lib/router.js b/lib/router.js index 38a1e81191..f4d5276ab2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3292,6 +3292,7 @@ router.get('/95mm/category/:category', require('./routes/95mm/category')); // 中国工程科技知识中心 router.get('/cktest/app/:ctgroup?/:domain?', require('./routes/cktest/app')); +router.get('/cktest/policy', require('./routes/cktest/policy')); // 妈咪帮 router.get('/mamibuy/:caty?/:age?/:sort?', require('./routes/mamibuy/index')); diff --git a/lib/routes/cktest/policy.js b/lib/routes/cktest/policy.js new file mode 100644 index 0000000000..ce0727bd6a --- /dev/null +++ b/lib/routes/cktest/policy.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = '1005'; + + const rootUrl = `http://mall.ckcest.cn/mall/listContent.ilf?dbId=${id}&text=&express=&secondSearchExpress=&order=3&page=1&limit=10`; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const list = response.data.results.datas.map((item) => ({ + link: item.detail_url, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + const dateArray = content('meta[name="firstpublishedtime"]').attr('content').split('-'); + const time = dateArray.pop(); + + item.pubDate = `${dateArray.join('-')} ${time}`; + item.title = content('title').text().split('_')[0]; + item.description = content('.wrap').html() || content('.policyLibraryOverview_content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '产业政策 - 中国工程科技知识中心', + link: rootUrl, + item: items, + }; +};