parent
2913df9d32
commit
ecba021f17
|
|
@ -754,6 +754,12 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
<Route author="kt286" example="/tprtc/news" path="/tprtc/news"/>
|
||||
|
||||
## 天眼查
|
||||
|
||||
### 热门搜索
|
||||
|
||||
<Route author="nczitzk" example="/tianyancha/hot" path="/tianyancha/hot" anticrawler="1"/>
|
||||
|
||||
## 无讼案例
|
||||
|
||||
### 案例
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue