feat(route): 东方财富网搜索关键词 (#12309)

* feat[route]: 东方财富网搜索关键词

* refactor: 设置描述内容

* fix: duplicate title

* refactor: add doc

* refactor: use api instead of puppeteer

* refactor: polish code

---------
This commit is contained in:
drgnchan
2023-04-15 00:30:56 +08:00
committed by GitHub
parent d6162ae973
commit 30e99fdd84
5 changed files with 69 additions and 0 deletions
+4
View File
@@ -258,6 +258,10 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re
<Route author="zidekuls" example="/eastmoney/ttjj/user/6551094298949188" path="/eastmoney/ttjj/user/:uid" :paramsDesc="['用户id, 可以通过天天基金App分享用户主页到浏览器,在相应的URL中找到']"/>
### 搜索
<Route author="drgnchan" example="/eastmoney/search/web3" path="/eastmoney/search/:keyword" :paramsDesc="['关键词,可以设置为自己需要检索的关键词']" radar="1"/>
## 法布财经
### 新闻
+1
View File
@@ -1,3 +1,4 @@
module.exports = {
'/ttjj/user/:uid': ['zidekuls'],
'/search/:keyword': ['drgnchan'],
};
+8
View File
@@ -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')}`,
},
],
},
};
+1
View File
@@ -1,3 +1,4 @@
module.exports = (router) => {
router.get('/ttjj/user/:uid', require('./ttjj/user'));
router.get('/search/:keyword', require('./search/index'));
};
+55
View File
@@ -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: '<em>',
postTag: '</em>',
},
},
};
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,
};
};