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, + }; +};