From 6c024346b93423850fcee026a010aff6acd33a96 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 8 Feb 2023 00:39:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E8=AF=81=E5=88=B8=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E7=BD=91=E6=A0=8F=E7=9B=AE=20(#11798)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route): 证券时报网栏目 * fix: no detail for files --- docs/finance.md | 56 +++++++++++++++++++------------------- lib/v2/stcn/index.js | 57 +++++++++++++++++---------------------- lib/v2/stcn/maintainer.js | 3 --- lib/v2/stcn/radar.js | 26 +++--------------- lib/v2/stcn/router.js | 2 +- 5 files changed, 59 insertions(+), 85 deletions(-) diff --git a/docs/finance.md b/docs/finance.md index 78ebfac4b..578e1f5d1 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -630,43 +630,45 @@ TokenInsight 官方亦有提供 RSS,可参考 + -| 要闻 | 滚动 | 深度 | 评论 | -| ------- | -- | ----- | ----- | -| xw/news | gd | xw/sd | xw/pl | +| 快讯 | 要闻 | 股市 | 公司 | 数据 | +| -- | -- | -- | ------- | ---- | +| kx | yw | gs | company | data | - +| 基金 | 金融 | 评论 | 产经 | 创投 | +| ---- | ------- | ------- | -- | -- | +| fund | finance | comment | cj | ct | -### 快讯 +| 科创板 | 新三板 | 投教 | ESG | 滚动 | +| --- | --- | -- | --- | -- | +| kcb | xsb | tj | zk | gd | - +| 股市一览 | 独家解读 | +| ---- | ---- | +| gsyl | djjd | -| 快讯 | e 公司 | 研报 | 时事 | 财经 | 券中社 | -| -- | ---- | -- | -- | -- | --- | -| | egs | yb | ss | cj | qzs | +| 公司新闻 | 公司动态 | +| ---- | ---- | +| gsxw | gsdt | - +| 独家数据 | 看点数据 | 资金流向 | 科创板 | 行情总貌 | +| ---- | ---- | ---- | ------ | ---- | +| djsj | kd | zj | sj_kcb | hq | -### 股市 +| 专栏 | 作者 | +| -- | ------ | +| zl | author | - +| 行业 | 汽车 | +| ---- | ---- | +| cjhy | cjqc | -| 股市 | 股市动态 | 独家解读 | -| -- | ---- | ---- | -| | gsdt | djjd | - - - -### 数据 - - - -| 数据 | 机器人新闻 | 独家数据 | -| -- | ----- | ---- | -| | jqrxw | djsj | +| 投教课堂 | 政策知识 | 投教动态 | 专题活动 | +| ---- | ---- | ---- | ---- | +| tjkt | zczs | tjdt | zthd | diff --git a/lib/v2/stcn/index.js b/lib/v2/stcn/index.js index 03d8fe7bb..a8de7b98c 100644 --- a/lib/v2/stcn/index.js +++ b/lib/v2/stcn/index.js @@ -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, }; diff --git a/lib/v2/stcn/maintainer.js b/lib/v2/stcn/maintainer.js index 30e113c7a..77e7f46e2 100644 --- a/lib/v2/stcn/maintainer.js +++ b/lib/v2/stcn/maintainer.js @@ -1,6 +1,3 @@ module.exports = { - '/data/:id?': ['nczitzk'], - '/kuaixun/:id?': ['nczitzk'], - '/stock/:id?': ['nczitzk'], '/:id?': ['nczitzk'], }; diff --git a/lib/v2/stcn/radar.js b/lib/v2/stcn/radar.js index c920b536f..efe59d3c7 100644 --- a/lib/v2/stcn/radar.js +++ b/lib/v2/stcn/radar.js @@ -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]}`, }, ], }, diff --git a/lib/v2/stcn/router.js b/lib/v2/stcn/router.js index 28f05970b..c7491b29f 100644 --- a/lib/v2/stcn/router.js +++ b/lib/v2/stcn/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w\d/-]+)?/, require('./index')); + router.get('/:id?', require('./index')); };