feat(route): add china.com finance' (#13473)

* fix china.com military xpath

* feat(route): add china.com finance

* feat(route): add china.com finance

* feat(route): add china.com finance

* fix(route): fix chinatime

* feat(route): add china.com finance

* feat(route): add china.com finance

* Update website/docs/routes/new-media.md

---------
This commit is contained in:
King
2023-10-09 04:37:14 +08:00
committed by GitHub
parent 3f31d29099
commit 46cf472b00
5 changed files with 87 additions and 0 deletions
+61
View File
@@ -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,
};
};
+1
View File
@@ -1,4 +1,5 @@
module.exports = {
'/finance/:category?': ['KingJem'],
'/news/military': ['jiaaoMario'],
'/news/:category?': ['jiaaoMario'],
};
+9
View File
@@ -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: '军事新闻',
+1
View File
@@ -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'));
};
+15
View File
@@ -327,6 +327,21 @@ Category of news
</Route>
### Finance News 财经 - 财经新闻 {#china.com-zhong-hua-wang-finance-news-cai-jing-cai-jing-xin-wen}
<Route author="KingJem" example="/china/finance" path="/china/finance/:category?" paramsDesc={['Category of news. See the form below for details, default is suggest news.']} radar="1">
| 推荐 | TMT | 金融 | 地产 | 消费 | 医药 | 酒业 | IPO观察 |
| ------- | --- | ------- | ------ | ------- | ----- | ---- | -------|
| tuijian | TMT | jinrong | dichan | xiaofei | yiyao | wine | IPO |
> Note: The default news num is `30`.
> 注意: 默认新闻条数是 `30`。
</Route>
## cnBeta.COM {#cnbeta.com}
### 头条资讯 {#cnbeta.com-tou-tiao-zi-xun}