diff --git a/docs/README.md b/docs/README.md index cb7741f63c..f8dc0bd85a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -608,6 +608,12 @@ RSSHub 提供下列 API 接口: + + +| 公告 | 新闻 | 研报 | +| ------------ | ---- | -------- | +| announcement | news | research | + ### 龙腾网 diff --git a/lib/router.js b/lib/router.js index e6027dc4b8..a74ea8bb32 100644 --- a/lib/router.js +++ b/lib/router.js @@ -463,6 +463,7 @@ router.get('/xueqiu/user/:id/:type?', require('./routes/xueqiu/user')); router.get('/xueqiu/favorite/:id', require('./routes/xueqiu/favorite')); router.get('/xueqiu/user_stock/:id', require('./routes/xueqiu/user_stock')); router.get('/xueqiu/fund/:id', require('./routes/xueqiu/fund')); +router.get('/xueqiu/stock_info/:id/:type?', require('./routes/xueqiu/stock_info')); // Greasy Fork router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts')); diff --git a/lib/routes/xueqiu/stock_info.js b/lib/routes/xueqiu/stock_info.js new file mode 100644 index 0000000000..f65b4c52ab --- /dev/null +++ b/lib/routes/xueqiu/stock_info.js @@ -0,0 +1,53 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const type = ctx.params.type || 'announcement'; + const count = 10; + const page = 1; + const typename = { + announcement: '公告', + news: '自选股新闻', + research: '研报', + }; + const source = typename[type]; + + const res1 = await axios({ + method: 'get', + url: `https://xueqiu.com/S/${id}`, + }); + const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0]; + + const $ = cheerio.load(res1.data); // 使用 cheerio 加载返回的 HTML + const html_title = $('title').text(); + const stock_name = html_title.split(' ')[0]; + + const res2 = await axios({ + method: 'get', + url: 'https://xueqiu.com/statuses/stock_timeline.json', + params: { + symbol_id: id, + source: source, + count: count, + page: page, + }, + headers: { + Cookie: token, + Referer: `https://xueqiu.com/u/${id}`, + }, + }); + + const data = res2.data.list; + ctx.state.data = { + title: `${stock_name} 的${source}`, + link: `https://xueqiu.com/S/${id}`, + description: `${stock_name} 的${source}`, + item: data.map((item) => ({ + title: item.title !== '' ? item.title : item.description.split('