mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): cbnc (#10924)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/rss/:id?': ['TonyRL'],
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
'cnbc.com': {
|
||||
_name: 'CNBC',
|
||||
search: [
|
||||
{
|
||||
title: '全文 RSS',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#cnbc',
|
||||
source: ['/rs/search/combinedcms/view.xml'],
|
||||
target: (_, url) => `/cnbc/rss/${new URL(url).searchParams.get('id')}`,
|
||||
},
|
||||
],
|
||||
www: [
|
||||
{
|
||||
title: '全文 RSS',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#cnbc',
|
||||
source: ['/id/:id/device/rss/rss.html'],
|
||||
target: '/cnbc/rss/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/rss/:id?', require('./rss'));
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const parser = require('@/utils/rss-parser');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id = '100003114' } = ctx.params;
|
||||
const feed = await parser.parseURL(`https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=${id}`);
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items
|
||||
.filter((i) => !i.link.startsWith('https://www.cnbc.com/select/'))
|
||||
.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
delete item.content;
|
||||
delete item.contentSnippet;
|
||||
delete item.isoDate;
|
||||
|
||||
item.description = '';
|
||||
if ($('.RenderKeyPoints-keyPoints').length) {
|
||||
$('.RenderKeyPoints-keyPoints').html();
|
||||
}
|
||||
if ($('.FeaturedContent-articleBody').length) {
|
||||
item.description += $('.FeaturedContent-articleBody').html();
|
||||
}
|
||||
if ($('.ArticleBody-articleBody').length) {
|
||||
item.description += $('.ArticleBody-articleBody').html();
|
||||
}
|
||||
if ($('.LiveBlogBody-articleBody').length) {
|
||||
item.description += $('.LiveBlogBody-articleBody').html();
|
||||
}
|
||||
if ($('.ClipPlayer-clipPlayer').length) {
|
||||
item.description += $('.ClipPlayer-clipPlayer').html();
|
||||
}
|
||||
|
||||
const meta = JSON.parse($('[type=application/ld+json]').last().text());
|
||||
item.author = meta.author ? (meta.author.name ? meta.author.name : meta.author.map((a) => a.name).join(', ')) : null;
|
||||
item.category = meta.keywords;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
language: feed.language,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user