diff --git a/README.md b/README.md index cd62a20cc5..469782da04 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 文章 - 大连工业大学 - 教务处新闻 +- 上海交通大学 + - 电子信息与电气工程学院 + - 学术动态 - 中国科学院 - 上海微系统与信息技术研究所 - 学术活动 diff --git a/docs/README.md b/docs/README.md index 9093f47732..f55daee698 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2223,6 +2223,14 @@ type,分类 参数: 无 +## 上海交通大学 + +### 电子信息与电气工程学院 -- 学术动态 + +举例: [https://rsshub.app/sjtu/seiee/academic](https://rsshub.app/sjtu/seiee/academic) + +路由: `/sjtu/seiee/academic` + ## 中国科学院 ### 上海微系统与信息技术研究所 -- 学术活动 diff --git a/router.js b/router.js index 90607f4e55..93efe3185b 100755 --- a/router.js +++ b/router.js @@ -473,6 +473,9 @@ router.get('/mygalgame', require('./routes/galgame/mygalgame')); // DPU router.get('/dpu/jiaowu/:type?', require('./routes/dpu/jiaowu')); +// 上海交通大学 +router.get('/sjtu/seiee/academic', require('./routes/sjtu/seiee/academic')); + // 中国科学院 router.get('/cas/sim/academic', require('./routes/cas/sim/academic')); diff --git a/routes/sjtu/seiee/academic.js b/routes/sjtu/seiee/academic.js new file mode 100644 index 0000000000..6a87fe848d --- /dev/null +++ b/routes/sjtu/seiee/academic.js @@ -0,0 +1,51 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://www.seiee.sjtu.edu.cn/'; + +module.exports = async (ctx) => { + const link = url.resolve(host, 'seiee/list/683-1-20.htm'); + const response = await axios.get(link); + + const $ = cheerio.load(response.data); + + const list = $('.list_style_1 li a') + .map((i, e) => $(e).attr('href')) + .get(); + + const out = await Promise.all( + list.map(async (itemUrl) => { + itemUrl = url.resolve(host, itemUrl); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + + const single = { + title: $('h2.title_3').text(), + link: itemUrl, + author: '上海交通大学电子信息与电气工程学院', + description: $('.c_1.article_content') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`), + pubDate: new Date( + $('.date_1 span:first-of-type') + .text() + .trim() + ), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '上海交通大学电子信息与电气工程学院 -- 学术动态', + link, + item: out, + }; +};