feat: add 中国工程科技知识中心产业政策 (#5864)

This commit is contained in:
Ethan Shen
2020-10-13 11:28:16 +01:00
committed by GitHub
parent 27269d898c
commit 6041624252
3 changed files with 49 additions and 0 deletions
+4
View File
@@ -825,6 +825,10 @@ type 为 all 时,category 参数不支持 cost 和 free
</Route>
### 产业政策
<Route author="nczitzk" example="/cktest/policy" path="/cktest/policy"/>
## 中国银行
### 中国银行外汇牌价
+1
View File
@@ -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'));
+44
View File
@@ -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,
};
};