From ecba021f1712124a2256297e02dfd8d859d8b69e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 4 Feb 2021 10:42:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=A4=A9=E7=9C=BC=E6=9F=A5?= =?UTF-8?q?=E7=83=AD=E9=97=A8=E6=90=9C=E7=B4=A2=20(#6837)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add 天眼查热门搜索 * docs: add anticrawler --- docs/other.md | 6 +++++ lib/router.js | 3 +++ lib/routes/tianyancha/hot.js | 49 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/routes/tianyancha/hot.js diff --git a/docs/other.md b/docs/other.md index 3f13ef6c8..f4f8c3839 100644 --- a/docs/other.md +++ b/docs/other.md @@ -754,6 +754,12 @@ type 为 all 时,category 参数不支持 cost 和 free +## 天眼查 + +### 热门搜索 + + + ## 无讼案例 ### 案例 diff --git a/lib/router.js b/lib/router.js index 5ac4caa32..e0b658e98 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3913,4 +3913,7 @@ router.get('/gov/mohrss/sbjm/:category?', require('./routes/gov/mohrss/sbjm')); router.get('/shinybbs/:id?', require('./routes/shinybbs/index')); router.get('/shinybbs/latest', require('./routes/shinybbs/latest')); +// 天眼查 +router.get('/tianyancha/hot', require('./routes/tianyancha/hot')); + module.exports = router; diff --git a/lib/routes/tianyancha/hot.js b/lib/routes/tianyancha/hot.js new file mode 100644 index 000000000..87d20b56f --- /dev/null +++ b/lib/routes/tianyancha/hot.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.tianyancha.com/'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.key') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.author = content('.resource').text().replace('来源:', ''); + item.description = content('.news-content').html(); + item.pubDate = date(content('.resource').next().text()); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '热门搜索 - 天眼查', + link: rootUrl, + item: items, + }; +};