增加21财经的频道RSS (#1855)
This commit is contained in:
parent
1ef6e38bba
commit
9091978f90
|
|
@ -209,3 +209,7 @@ category 对应的关键词有
|
|||
## 半月谈
|
||||
|
||||
<Route name="板块" author="LogicJake" example="/banyuetan/jicengzhili" path="/banyuetan/:name" :paramsDesc="['板块名称,可在 URL 中找到']"/>
|
||||
|
||||
## 21 财经
|
||||
|
||||
<Route name="频道" author="brilon" example="/21caijing/channel/readnumber" path="/21caijing/channel/:name" :paramsDesc="['频道名称,可在[https://m.21jingji.com/](https://m.21jingji.com/)页面URL中找到']"/>
|
||||
|
|
|
|||
|
|
@ -1237,4 +1237,7 @@ router.get('/mobdata/report', require('./routes/mobdata/report'));
|
|||
// 谷雨
|
||||
router.get('/tencent/guyu/channel/:name', require('./routes/tencent/guyu/channel'));
|
||||
|
||||
// 21财经
|
||||
router.get('/21caijing/channel/:name', require('./routes/21caijing/channel'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const date = require('../../utils/date');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const channel = ctx.params.name;
|
||||
const pageUrl = `https://m.21jingji.com/channel/${channel}`;
|
||||
|
||||
const response = await axios({
|
||||
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 Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: link,
|
||||
headers: {
|
||||
Referer: pageUrl,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
$('img').each((index, elem) => {
|
||||
const $elem = $(elem);
|
||||
const src = $elem.attr('data-original');
|
||||
if (src) {
|
||||
$elem.attr('src', src);
|
||||
$elem.removeAttr('data-original');
|
||||
}
|
||||
});
|
||||
|
||||
const div = $('div.editor');
|
||||
if (div) {
|
||||
div.remove();
|
||||
}
|
||||
|
||||
const title = $('h1').text();
|
||||
const dateStr = $('div.newsDate').text();
|
||||
const content = $('div.txtContent').html();
|
||||
|
||||
const single = {
|
||||
pubDate: date(dateStr),
|
||||
link: link,
|
||||
title: title,
|
||||
description: content,
|
||||
};
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '21财经-' + channelName,
|
||||
link: pageUrl,
|
||||
description: '21财经-' + channelName,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue