mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 21:18:57 +08:00
feat: add cfan news (#2929)
This commit is contained in:
@@ -62,6 +62,12 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="kt286" example="/bof/home" path="/bof/home" />
|
<Route author="kt286" example="/bof/home" path="/bof/home" />
|
||||||
|
|
||||||
|
## cfan
|
||||||
|
|
||||||
|
### 新闻
|
||||||
|
|
||||||
|
<Route author="kt286" example="/cfan/news" path="/cfan/news"/>
|
||||||
|
|
||||||
## checkee.info
|
## checkee.info
|
||||||
|
|
||||||
### 美国签证 check 动态
|
### 美国签证 check 动态
|
||||||
|
|||||||
@@ -1653,4 +1653,7 @@ router.get('/cneb/guoneinews', require('./routes/cneb/guoneinews'));
|
|||||||
// 邮箱
|
// 邮箱
|
||||||
router.get('/mail/imap/:email', require('./routes/mail/imap'));
|
router.get('/mail/imap/:email', require('./routes/mail/imap'));
|
||||||
|
|
||||||
|
// cfan
|
||||||
|
router.get('/cfan/news', require('./routes/cfan/news'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
52
lib/routes/cfan/news.js
Normal file
52
lib/routes/cfan/news.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const { addNoReferrer } = require('@/utils/common-utils');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const pageUrl = 'http://www.cfan.com.cn/news/';
|
||||||
|
const response = await got.get(pageUrl);
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const list = $('.ui-video-list').get();
|
||||||
|
|
||||||
|
const ProcessFeed = async (link) => {
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: link,
|
||||||
|
});
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
addNoReferrer($, '.maincontent');
|
||||||
|
|
||||||
|
return $('.maincontent').html() || '文章已被删除';
|
||||||
|
};
|
||||||
|
|
||||||
|
const items = await Promise.all(
|
||||||
|
list.map(async (item) => {
|
||||||
|
const $ = cheerio.load(item);
|
||||||
|
const link = $('.left-post a').attr('href');
|
||||||
|
|
||||||
|
const cache = await ctx.cache.get(link);
|
||||||
|
if (cache) {
|
||||||
|
return Promise.resolve(JSON.parse(cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
const description = await ProcessFeed(link);
|
||||||
|
|
||||||
|
const single = {
|
||||||
|
title: $('.left-post-title').text(),
|
||||||
|
description,
|
||||||
|
link: link,
|
||||||
|
pubDate: new Date($('.left-post-date').text()).toUTCString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.cache.set(link, JSON.stringify(single));
|
||||||
|
return Promise.resolve(single);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: $('title').text(),
|
||||||
|
link: pageUrl,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user