diff --git a/docs/finance.md b/docs/finance.md index 2dbd225511..9fd587df85 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -258,6 +258,10 @@ TokenInsight 官方亦有提供 RSS,可参考 +### 搜索 + + + ## 法布财经 ### 新闻 diff --git a/lib/v2/eastmoney/maintainer.js b/lib/v2/eastmoney/maintainer.js index abe1224b72..a1e0043522 100644 --- a/lib/v2/eastmoney/maintainer.js +++ b/lib/v2/eastmoney/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/ttjj/user/:uid': ['zidekuls'], + '/search/:keyword': ['drgnchan'], }; diff --git a/lib/v2/eastmoney/radar.js b/lib/v2/eastmoney/radar.js index f738351e2a..a7ff7f8ee7 100644 --- a/lib/v2/eastmoney/radar.js +++ b/lib/v2/eastmoney/radar.js @@ -9,5 +9,13 @@ module.exports = { target: (_param, url) => `/eastmoney/ttjj/user/${new URL(url).searchParams.get('userid')}`, }, ], + so: [ + { + title: '搜索', + docs: 'https://docs.rsshub.app/finance.html#dong-fang-cai-fu', + source: ['/News/s'], + target: (_param, url) => `/eastmoney/search/${new URL(url).searchParams.get('KeyWord')}`, + }, + ], }, }; diff --git a/lib/v2/eastmoney/router.js b/lib/v2/eastmoney/router.js index 1bd4ddbd7d..8d86a8aae1 100644 --- a/lib/v2/eastmoney/router.js +++ b/lib/v2/eastmoney/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { router.get('/ttjj/user/:uid', require('./ttjj/user')); + router.get('/search/:keyword', require('./search/index')); }; diff --git a/lib/v2/eastmoney/search/index.js b/lib/v2/eastmoney/search/index.js new file mode 100644 index 0000000000..14116f2eee --- /dev/null +++ b/lib/v2/eastmoney/search/index.js @@ -0,0 +1,55 @@ +const { parseDate } = require('@/utils/parse-date'); +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const keyword = ctx.params.keyword; + const link = `https://so.eastmoney.com/News/s?KeyWord=${keyword}`; + const body = { + uid: '', + keyword, + type: ['cmsArticleWebOld'], + client: 'web', + clientType: 'web', + clientVersion: 'curr', + params: { + cmsArticleWebOld: { + searchScope: 'default', + sort: 'default', + pageIndex: 1, + pageSize: 10, + preTag: '', + postTag: '', + }, + }, + }; + const cb = `jQuery${('3.5.1' + Math.random()).replace(/\D/g, '')}_${Date.now()}`; + + const url = `https://search-api-web.eastmoney.com/search/jsonp`; + + const response = await got(url, { + searchParams: { + cb, + param: JSON.stringify(body), + }, + }); + const data = response.data; + + const extractedText = data.match(/jQuery\d+_\d+\((.*)\)/)[1]; + + const obj = JSON.parse(extractedText); + const arr = obj.result.cmsArticleWebOld; + + const items = arr.map((item) => ({ + title: item.title, + description: item.content, + pubDate: timezone(parseDate(item.date), 8), + link: item.url, + author: item.mediaName, + })); + ctx.state.data = { + title: `东方财富网 - 搜索'${keyword}'`, + link, + item: items, + }; +};