feat: add 每经网分类 (#6896)

This commit is contained in:
Ethan Shen 2021-02-14 02:55:45 +08:00 committed by GitHub
parent 26d28b2d43
commit f50159ea23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 8 deletions

View File

@ -66,7 +66,7 @@ pageClass: routes
### 搜索关键字
<Route author="nczitzk" example="/gelonghui/keyword/ 早报" path="/gelonghui/keyword/:keyword" :paramsDesc="[' 搜索关键字']/>
<Route author="nczitzk" example="/gelonghui/keyword/早报" path="/gelonghui/keyword/:keyword" :paramsDesc="['搜索关键字']"/>
## 金十数据
@ -81,6 +81,22 @@ pageClass: routes
</Route>
## 每经网
### 分类
<Route author="nczitzk" example="/nbd" path="/nbd/:id?" :paramsDesc="['分类 id见下表默认为要闻']">
| 头条 | 要闻 | 图片新闻 | 推荐 |
| ---- | ---- | -------- | ---- |
| 2 | 3 | 4 | 5 |
</Route>
### 重磅原创
<Route author="MeXunco" example="/nbd/daily" path="/nbd/daily"/>
## 上海证券交易所
### 本所业务规则

View File

@ -613,12 +613,6 @@ category 对应的关键词有
</Route>
## 每经网
### 重磅原创
<Route author="MeXunco" example="/nbd/daily" path="/nbd/daily" />
## 南方周末
### 新闻分类

View File

@ -2246,8 +2246,9 @@ router.get('/wineyun/:category', require('./routes/wineyun'));
router.get('/xiaohongshu/user/:user_id/:category', require('./routes/xiaohongshu/user'));
router.get('/xiaohongshu/board/:board_id', require('./routes/xiaohongshu/board'));
// 重磅原创-每经网
// 每经网
router.get('/nbd/daily', require('./routes/nbd/article'));
router.get('/nbd/:id?', require('./routes/nbd/index'));
// 快知
router.get('/kzfeed/topic/:id', require('./routes/kzfeed/topic'));

50
lib/routes/nbd/index.js Normal file
View File

@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id || '3';
const rootUrl = 'http://www.nbd.com.cn';
const currentUrl = `${rootUrl}/columns/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.u-news-title a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.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.description = content('.g-articl-text').html();
item.pubDate = new Date(detailResponse.data.match(/"pubDate": "(.*)"/)[1]).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: `${$('.u-channelname').text()} - 每经网`,
link: currentUrl,
item: items,
};
};