From f791d27d8577a621728d17aa85d145743f9af598 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Mon, 4 Mar 2019 19:14:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9B=AA=E7=90=83=E8=82=A1?= =?UTF-8?q?=E7=A5=A8=E7=9A=84=E5=85=AC=E5=91=8A=EF=BC=8C=E7=A0=94=E6=8A=A5?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E9=97=BB=20(#1671)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 ++++ lib/router.js | 1 + lib/routes/xueqiu/stock_info.js | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 lib/routes/xueqiu/stock_info.js 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('