mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 23:42:40 +08:00
feat: add route for ofweek (#5789)
This commit is contained in:
@@ -701,6 +701,12 @@ area 分区选项
|
||||
|
||||
</Route>
|
||||
|
||||
## 高科技行业门户
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="luyuhuang" example="/ofweek/news" path="/ofweek/news"/>
|
||||
|
||||
## 谷歌新闻
|
||||
|
||||
### 新闻
|
||||
|
||||
@@ -3302,4 +3302,7 @@ router.get('/gamer/gnn/:category?', require('./routes/gamer/gnn_index'));
|
||||
// 中国人大网
|
||||
router.get('/npc/:caty', require('./routes/npc/index'));
|
||||
|
||||
// 高科技行业门户
|
||||
router.get('/ofweek/news', require('./routes/ofweek/news'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: 'https://www.ofweek.com/CATList-8100-CHANGYIEXINWE.html',
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
||||
const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
|
||||
const list = $('div.list-left div.con-details h3 > a')
|
||||
.slice(0, 20)
|
||||
.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 res = await got({ method: 'get', url: item.link, responseType: 'buffer' });
|
||||
const content = cheerio.load(iconv.decode(res.data, 'gbk'));
|
||||
const artical = content('div.artical');
|
||||
item.description = artical.find('#articleC').html();
|
||||
item.author = artical.find('div.source-name').text();
|
||||
item.pubDate = artical.find('div.time.fl').text();
|
||||
item.pubDate = new Date(item.pubDate + ' GMT+8').toUTCString();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '高科技行业门户',
|
||||
link: 'https://www.ofweek.com/CATList-8100-CHANGYIEXINWE.html',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user