feat(route): add 21财经频道 (#18048)
* feat(route): add 21财经频道 * fix: Remove complex expressions
This commit is contained in:
parent
f715d22f6c
commit
acda82f385
|
|
@ -587,7 +587,7 @@ router.get('/checkee/:dispdate', lazyloadRouteHandler('./routes/checkee/index'))
|
|||
router.get('/gushiwen/recommend/:annotation?', lazyloadRouteHandler('./routes/gushiwen/recommend'));
|
||||
|
||||
// 21财经
|
||||
router.get('/21caijing/channel/:name', lazyloadRouteHandler('./routes/21caijing/channel'));
|
||||
// router.get('/21caijing/channel/:name', lazyloadRouteHandler('./routes/21caijing/channel'));
|
||||
|
||||
// 北京邮电大学
|
||||
router.get('/bupt/yz/:type', lazyloadRouteHandler('./routes/universities/bupt/yz'));
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const { parseRelativeDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const channel = ctx.params.name;
|
||||
const pageUrl = `https://m.21jingji.com/channel/${channel}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: pageUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const channelName = $(`div.nav a[href='/channel/${channel}']`).text();
|
||||
const list = $('div.news_list>a')
|
||||
.slice(0, 5)
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (link) => {
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return JSON.parse(cache);
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
headers: {
|
||||
Referer: pageUrl,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const div = $('div.editor');
|
||||
if (div) {
|
||||
div.remove();
|
||||
}
|
||||
|
||||
const title = $('h1').text();
|
||||
const dateStr = $('div.newsDate').text();
|
||||
|
||||
$('div.txtContent img').each((index, element) => {
|
||||
const $el = $(element);
|
||||
const img_original_data = $el.attr('data-original');
|
||||
const img_src = $el.attr('src');
|
||||
if (img_src === undefined && img_original_data) {
|
||||
$el.attr('src', img_original_data);
|
||||
}
|
||||
});
|
||||
|
||||
const content = $('div.txtContent').html();
|
||||
|
||||
const single = {
|
||||
pubDate: timezone(parseRelativeDate(dateStr), +8),
|
||||
link,
|
||||
title,
|
||||
description: content,
|
||||
};
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return single;
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '21财经-' + channelName,
|
||||
link: pageUrl,
|
||||
description: '21财经-' + channelName,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,8 @@
|
|||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: '21财经',
|
||||
url: '21caijing.com',
|
||||
categories: ['finance'],
|
||||
description: '',
|
||||
};
|
||||
Loading…
Reference in New Issue