From 1fa27701aa14834dfaec13618c856032ebe62ef6 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Thu, 5 Sep 2019 12:04:22 +0800 Subject: [PATCH] feat: crawl stock's hot statuses (#2995) * crawl 36kr newsflashes * xueqiu hot statuses * crawl stock's hot statuses --- lib/routes/xueqiu/stock_info.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/routes/xueqiu/stock_info.js b/lib/routes/xueqiu/stock_info.js index 11cefc79d..17a336bda 100644 --- a/lib/routes/xueqiu/stock_info.js +++ b/lib/routes/xueqiu/stock_info.js @@ -10,6 +10,7 @@ module.exports = async (ctx) => { announcement: '公告', news: '自选股新闻', research: '研报', + all: 'all', }; const source = typename[type]; @@ -21,16 +22,27 @@ module.exports = async (ctx) => { const $ = cheerio.load(res1.data); // 使用 cheerio 加载返回的 HTML const html_title = $('title').text(); - const stock_name = html_title.split(' ')[0]; + const stock_name = html_title.split('(')[0]; + + let query_url = 'https://xueqiu.com/statuses'; + if (source === 'all') { + query_url += '/search.json'; + } else { + query_url += '/stock_timeline.json'; + } const res2 = await got({ method: 'get', - url: 'https://xueqiu.com/statuses/stock_timeline.json', + url: query_url, params: { symbol_id: id, + symbol: id, source: source, count: count, page: page, + sort: 'alpha', + comment: '0', + hl: '0', }, headers: { Cookie: token, @@ -40,11 +52,11 @@ module.exports = async (ctx) => { const data = res2.data.list; ctx.state.data = { - title: `${stock_name} 的${source}`, + 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(']+>/g, '').slice(0, 30), description: item.description, pubDate: new Date(item.created_at).toUTCString(), link: `https://xueqiu.com${item.target}`,