feat: add futunn lighlights (#4945)
This commit is contained in:
@@ -36,6 +36,12 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/cls/depth" path="/cls/depth"/>
|
||||
|
||||
## 富途牛牛
|
||||
|
||||
### 要闻
|
||||
|
||||
<Route author="Wsine" example="/futunn/highlights" path="/futunn/highlights" />
|
||||
|
||||
## 淘股吧股票论坛
|
||||
|
||||
### 论坛总版
|
||||
|
||||
@@ -2838,4 +2838,7 @@ router.get('/gov/chinatax/latest', require('./routes/gov/chinatax/latest'));
|
||||
// 荔枝FM
|
||||
router.get('/lizhi/user/:id', require('./routes/lizhi/user'));
|
||||
|
||||
// 富途牛牛
|
||||
router.get('/futunn/highlights', require('./routes/futunn/highlights'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const date_util = require('@/utils/date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = `https://news.futunn.com/main`;
|
||||
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
// extract json from 'window._params = {...};'
|
||||
const params = $('script:not([src])').html().trim().slice(17, -1);
|
||||
|
||||
const newslist = JSON.parse(params).preList;
|
||||
|
||||
const out = await Promise.all(
|
||||
newslist.map(async (info) => {
|
||||
const title = info.title;
|
||||
const itemUrl = info.url;
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
url: itemUrl,
|
||||
method: 'get',
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const description = $('div.newsDetailBox div.main div.inner').html() || '原文已被删除';
|
||||
|
||||
const date = $('div.timeBar').text();
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
link: itemUrl,
|
||||
description: description,
|
||||
pubDate: date_util(date, 8),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `富途牛牛要闻`,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user