diff --git a/lib/v2/china/finance/finance.js b/lib/v2/china/finance/finance.js index e69de29bb..d76595ff4 100644 --- a/lib/v2/china/finance/finance.js +++ b/lib/v2/china/finance/finance.js @@ -0,0 +1,61 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const CATEGORY_MAP = { + tuijian: 'tuijian', // 推荐 + TMT: 'TMT', // TMT + jinrong: 'jinrong', // 金融 + dichan: 'dichan', // 地产 + xiaofei: 'xiaofei', // 消费 + yiyao: 'yiyao', // 医药 + wine: 'wine', // 酒业 + IPO: 'IPO', // IPO观察 +}; + +module.exports = async (ctx) => { + const baseUrl = 'https://finance.china.com'; + const category = CATEGORY_MAP[ctx.params.category] ?? CATEGORY_MAP.tuijian; + const websiteUrl = `${baseUrl}/${category}`; + const response = await got(websiteUrl); + const data = response.data; + const $ = cheerio.load(data); + const categoryTitle = $('.list-hd strong').text(); + const listCategory = `中华网-财经-${categoryTitle}新闻`; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; + const detailsUrls = $('.item-con-inner') + .map((_, item) => { + item = $(item); + return { + link: item.find('.tit>a').attr('href'), + }; + }) + .get() + .filter((item) => item.link !== void 0) + .slice(0, limit); + + const items = await Promise.all( + detailsUrls.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailsResponse = await got(item.link); + const $d = cheerio.load(detailsResponse.data); + return { + title: $d('.article_title').text(), + link: item.link, + description: $d('#js_article_content').html(), + pubDate: timezone(parseDate($d('.article_info>span.time').text()), +8), + author: $d(' div.article_info > span.source').text(), + category: listCategory, + }; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link: websiteUrl, + category: listCategory, + item: items, + }; +}; diff --git a/lib/v2/china/maintainer.js b/lib/v2/china/maintainer.js index 3a51c3f62..7f53f1ef1 100644 --- a/lib/v2/china/maintainer.js +++ b/lib/v2/china/maintainer.js @@ -1,4 +1,5 @@ module.exports = { + '/finance/:category?': ['KingJem'], '/news/military': ['jiaaoMario'], '/news/:category?': ['jiaaoMario'], }; diff --git a/lib/v2/china/radar.js b/lib/v2/china/radar.js index 0aa5e7d0f..cd55b416b 100644 --- a/lib/v2/china/radar.js +++ b/lib/v2/china/radar.js @@ -1,6 +1,15 @@ module.exports = { 'china.com': { _name: '中华网', + + finance: [ + { + title: '财经新闻', + docs: 'https://docs.rsshub.app/routes/new-media#zhong-hua-wang', + source: '/:category', + target: '/china/finance/:category?', + }, + ], military: [ { title: '军事新闻', diff --git a/lib/v2/china/router.js b/lib/v2/china/router.js index 3008787af..bbc319ce3 100644 --- a/lib/v2/china/router.js +++ b/lib/v2/china/router.js @@ -1,4 +1,5 @@ module.exports = (router) => { + router.get('/finance/:category?', require('./finance/finance.js')); router.get('/news/military', require('./news/military/news.js')); router.get('/news/:category?', require('./news/highlights/news.js')); }; diff --git a/website/docs/routes/new-media.md b/website/docs/routes/new-media.md index 5e8198f13..7e1bbcdf2 100644 --- a/website/docs/routes/new-media.md +++ b/website/docs/routes/new-media.md @@ -327,6 +327,21 @@ Category of news + +### Finance News 财经 - 财经新闻 {#china.com-zhong-hua-wang-finance-news-cai-jing-cai-jing-xin-wen} + + + +| 推荐 | TMT | 金融 | 地产 | 消费 | 医药 | 酒业 | IPO观察 | +| ------- | --- | ------- | ------ | ------- | ----- | ---- | -------| +| tuijian | TMT | jinrong | dichan | xiaofei | yiyao | wine | IPO | + +> Note: The default news num is `30`. + +> 注意: 默认新闻条数是 `30`。 + + + ## cnBeta.COM {#cnbeta.com} ### 头条资讯 {#cnbeta.com-tou-tiao-zi-xun}