feat: add 消费明鉴最新新闻 (#5549)

This commit is contained in:
Ethan Shen
2020-08-28 21:38:07 +01:00
committed by GitHub
parent c2163bf044
commit 1cef38251b
3 changed files with 56 additions and 0 deletions
+6
View File
@@ -227,6 +227,12 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
<Route author="LogicJake" example="/weidian/goods/431508863" path="/weidian/goods/:id" :paramsDesc="['商铺 id']"/>
## 消费明鉴
### 最新新闻
<Route author="nczitzk" example="/mingjian" path="/mingjian"/>
## 消费者报道
### 要闻
+3
View File
@@ -3119,4 +3119,7 @@ router.get('/fjnews/fz/30', require('./routes/fjnews/fznews'));
// 九江新闻jjnews
router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews'));
// 消费明鉴
router.get('/mingjian', require('./routes/mingjian/index'));
module.exports = router;
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = 'https://www.mingjian.cn/';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.col-md-3')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
link: a.attr('href'),
};
})
.get();
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);
item.title = content('div.title').eq(0).text();
item.description = content('div.content').html();
item.pubDate = new Date(content('div.date').eq(0).text().replace('发表于', '') + ' GMT+8').toUTCString();
return item;
})
)
);
ctx.state.data = {
title: '消费明鉴 - 最新新闻',
link: currentUrl,
item: items,
};
};