mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-17 03:58:49 +08:00
增加新京报订阅及其与3DM的说明文档 (#297)
* Add 3dm news center. * Modify router name, fix timezone issue. * Add entries in Readme. Add 新京报
This commit is contained in:
@@ -137,6 +137,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
||||
- UU 看书
|
||||
- 小说章节
|
||||
- 3dm
|
||||
- 新闻中心
|
||||
- 新闻
|
||||
- 攻略
|
||||
- 下载
|
||||
@@ -150,6 +151,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
||||
- 学术讲座
|
||||
- 通知公告
|
||||
- 教务信息
|
||||
- 新京报
|
||||
- 快讯
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
||||
@@ -1087,6 +1087,14 @@ language,语言,可在 [Trending 页](https://github.com/trending/javascript
|
||||
|
||||
## 3dm
|
||||
|
||||
### 新闻中心
|
||||
|
||||
举例: [https://rsshub.app/3dm/news](https://rsshub.app/3dm/news)
|
||||
|
||||
路由: `/3dm/news`
|
||||
|
||||
参数: 无
|
||||
|
||||
### 新闻
|
||||
|
||||
举例: [https://rsshub.app/3dm/detroitbecomehuman/news](https://rsshub.app/3dm/detroitbecomehuman/news)
|
||||
@@ -1182,3 +1190,11 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
|
||||
路由: `/shmtu/jwc/:type`
|
||||
|
||||
参数: type,1 为教务新闻,2 为教务公告
|
||||
|
||||
## 新京报
|
||||
|
||||
举例: [https://rsshub.app/bjnews/realtime](https://rsshub.app/bjnews/realtime)
|
||||
|
||||
路由: `/bjnews/:category`
|
||||
|
||||
参数: category,新京报的栏目名,点击对应栏目后在地址栏找到
|
||||
|
||||
@@ -302,4 +302,7 @@ router.get('/shmtu/events', require('./routes/shmtu/events'));
|
||||
router.get('/shmtu/notes', require('./routes/shmtu/notes'));
|
||||
router.get('/shmtu/jwc/:type', require('./routes/shmtu/jwc'));
|
||||
|
||||
// 新京报
|
||||
router.get('/bjnews/:cat', require('./routes/bjnews/news'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
51
routes/bjnews/news.js
Normal file
51
routes/bjnews/news.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
const axios_ins = axios.create({
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
},
|
||||
});
|
||||
module.exports = async (ctx) => {
|
||||
const url = `http://www.bjnews.com.cn/${ctx.params.cat}`;
|
||||
const res = await axios_ins.get(url);
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('#news_ul li');
|
||||
const out = [];
|
||||
const proList = [];
|
||||
let time, title, itemUrl;
|
||||
for (let i = 0; i < (list.length <= 20 ? list.length : 20); i++) {
|
||||
const $ = cheerio.load(list[i]);
|
||||
time = $('p').text();
|
||||
title = $('a').text();
|
||||
itemUrl = $('a').attr('href');
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
out.push(cache);
|
||||
continue;
|
||||
}
|
||||
const single = {
|
||||
title: title,
|
||||
pubDate: new Date(time).toUTCString(),
|
||||
link: itemUrl,
|
||||
guid: itemUrl,
|
||||
};
|
||||
out.push(single);
|
||||
ctx.cache.set(itemUrl, single, 24 * 60 * 60);
|
||||
proList.push(axios_ins.get(itemUrl));
|
||||
}
|
||||
const responses = await axios.all(proList);
|
||||
for (let i = 0; i < responses.length; i++) {
|
||||
const res = responses[i];
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
out[i].description = $('#main .content').html();
|
||||
}
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user