fix(route): 证券时报网栏目 (#11798)

* fix(route): 证券时报网栏目

* fix: no detail for files
This commit is contained in:
Ethan Shen 2023-02-08 00:39:07 +08:00 committed by GitHub
parent 51031e7184
commit 6c024346b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 85 deletions

View File

@ -630,43 +630,45 @@ TokenInsight 官方亦有提供 RSS可参考 <https://api.tokeninsight.com/re
## 证券时报网
### 要闻
### 栏目
<Route author="nczitzk" example="/stcn/xw/news" path="/stcn/:id?" :paramsDesc="['分类 id见下表默认为要闻']">
<Route author="nczitzk" example="/stcn/yw" path="/stcn/:id?" :paramsDesc="['栏目 id见下表默认为要闻']">
| 要闻 | 滚动 | 深度 | 评论 |
| ------- | -- | ----- | ----- |
| xw/news | gd | xw/sd | xw/pl |
| 快讯 | 要闻 | 股市 | 公司 | 数据 |
| -- | -- | -- | ------- | ---- |
| kx | yw | gs | company | data |
</Route>
| 基金 | 金融 | 评论 | 产经 | 创投 |
| ---- | ------- | ------- | -- | -- |
| fund | finance | comment | cj | ct |
### 快讯
| 科创板 | 新三板 | 投教 | ESG | 滚动 |
| --- | --- | -- | --- | -- |
| kcb | xsb | tj | zk | gd |
<Route author="nczitzk" example="/stcn/kuaixun" path="/stcn/kuaixun/:id?" :paramsDesc="['分类 id见下表默认为快讯']">
| 股市一览 | 独家解读 |
| ---- | ---- |
| gsyl | djjd |
| 快讯 | e 公司 | 研报 | 时事 | 财经 | 券中社 |
| -- | ---- | -- | -- | -- | --- |
| | egs | yb | ss | cj | qzs |
| 公司新闻 | 公司动态 |
| ---- | ---- |
| gsxw | gsdt |
</Route>
| 独家数据 | 看点数据 | 资金流向 | 科创板 | 行情总貌 |
| ---- | ---- | ---- | ------ | ---- |
| djsj | kd | zj | sj_kcb | hq |
### 股市
| 专栏 | 作者 |
| -- | ------ |
| zl | author |
<Route author="nczitzk" example="/stcn/stock" path="/stcn/stock/:id?" :paramsDesc="['分类 id见下表默认为股市']">
| 行业 | 汽车 |
| ---- | ---- |
| cjhy | cjqc |
| 股市 | 股市动态 | 独家解读 |
| -- | ---- | ---- |
| | gsdt | djjd |
</Route>
### 数据
<Route author="nczitzk" example="/stcn/data" path="/stcn/data/:id?" :paramsDesc="['分类 id见下表默认为数据']">
| 数据 | 机器人新闻 | 独家数据 |
| -- | ----- | ---- |
| | jqrxw | djsj |
| 投教课堂 | 政策知识 | 投教动态 | 专题活动 |
| ---- | ---- | ---- | ---- |
| tjkt | zczs | tjdt | zthd |
</Route>

View File

@ -3,60 +3,53 @@ const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const shortcuts = {
'news/news': 'xw/news',
'news/gd': 'gd',
'news/sd': 'xw/sd',
'news/pl': 'xw/pl',
'data/data': 'data',
};
module.exports = async (ctx) => {
let path = ctx.path.replace(/\//, '');
if (shortcuts.hasOwnProperty(path)) {
path = shortcuts[path];
}
const id = ctx.params.id ?? 'yw';
const rootUrl = 'https://www.stcn.com';
const currentUrl = `${rootUrl}/${path || 'xw/news'}`;
const currentUrl = `${rootUrl}/article/list/${id}.html`;
const apiUrl = `${rootUrl}/article/list.html?type=${id}`;
const response = await got({
method: 'get',
url: currentUrl,
url: apiUrl,
});
const match = response.data.match(/var curr_channel_id = "(light_\d+)";/);
const $ = cheerio.load(response.data);
$('.website, .websit').remove();
let items = $('.box_left, .box_left2, .left2')
.find('a[title]')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
let items = $('.t, .tt, .title')
.find('a')
.toArray()
.map((item) => {
item = $(item);
const link = item.attr('href');
return {
title: item.text(),
link: item.attr('href').replace(/^\.\./, currentUrl.split('/').slice(0, -1).join('/')).replace(/^\./, currentUrl),
title: item.text().replace(/(^【|】$)/g, ''),
link: /^http/.test(link) ? link : `${rootUrl}${link}`,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
if (/\.html$/.test(item.link)) {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const content = cheerio.load(detailResponse.data);
item.description = content('.txt_con').html();
item.author = content('meta[name="author"]').attr('content');
item.category = content('meta[name="keywords"]').attr('content').split(';');
item.pubDate = timezone(parseDate(detailResponse.data.match(/publishdate = '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})';/)[1]), +8);
item.title = content('.detail-title').text();
item.author = content('.detail-info span').first().text().split('').pop();
item.pubDate = timezone(parseDate(content('.detail-info span').last().text()), +8);
item.category = content('.detail-content-tags div')
.toArray()
.map((t) => content(t).text());
item.description = content('.detail-content').html();
}
return item;
})
@ -64,7 +57,7 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: `${(match ? $('#' + match[1]).text() : '') || $('.cur').text()} - 证券时报网`,
title: `证券时报网 - ${$('.breadcrumb a').last().text()}`,
link: currentUrl,
item: items,
};

View File

@ -1,6 +1,3 @@
module.exports = {
'/data/:id?': ['nczitzk'],
'/kuaixun/:id?': ['nczitzk'],
'/stock/:id?': ['nczitzk'],
'/:id?': ['nczitzk'],
};

View File

@ -3,28 +3,10 @@ module.exports = {
_name: '证券时报网',
'.': [
{
title: '要闻',
docs: 'https://docs.rsshub.app/finance.html#zheng-quan-shi-bao-wang-yao-wen',
source: ['/xw/:id', '/gd', '/'],
target: (params, url) => `/stcn${new URL(url).pathname}`,
},
{
title: '快讯',
docs: 'https://docs.rsshub.app/finance.html#zheng-quan-shi-bao-wang-kuai-xun',
source: ['/kuaixun/:id', '/kuaixun', '/'],
target: (params, url) => `/stcn${new URL(url).pathname}`,
},
{
title: '股市',
docs: 'https://docs.rsshub.app/finance.html#zheng-quan-shi-bao-wang-gu-shi',
source: ['/stock/:id', '/stock', '/'],
target: (params, url) => `/stcn${new URL(url).pathname}`,
},
{
title: '数据',
docs: 'https://docs.rsshub.app/finance.html#zheng-quan-shi-bao-wang-shu-ju',
source: ['/data/:id', '/data', '/'],
target: (params, url) => `/stcn${new URL(url).pathname}`,
title: '栏目',
docs: 'https://docs.rsshub.app/finance.html#zheng-quan-shi-bao-wang-lan-mu',
source: ['/'],
target: (params, url) => `/stcn/${new URL(url).toString().match(/article\/list\/(.*)\.html/)[1]}`,
},
],
},

View File

@ -1,3 +1,3 @@
module.exports = function (router) {
router.get(/([\w\d/-]+)?/, require('./index'));
router.get('/:id?', require('./index'));
};