mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 22:19:40 +08:00
feat: add 西安交通大学教务处 (#4085)
This commit is contained in:
@@ -1076,6 +1076,24 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
|
||||
|
||||
</Route>
|
||||
|
||||
## 西安交通大学
|
||||
|
||||
### 教务处
|
||||
|
||||
<Route author="hoilc" example="/xjtu/dean/jxxx/xytz/ksap" path="/xjtu/dean/:subpath+" :paramsDesc="['栏目路径, 支持多级, 不包括末尾的`.htm`']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
支持`http://dean.xjtu.edu.cn/`下所有**有文章列表**的栏目,
|
||||
|
||||
例如`http://dean.xjtu.edu.cn/gzlc.htm`, 则`subpath`为`gzlc`
|
||||
|
||||
又例`http://dean.xjtu.edu.cn/jxxx/xytz.htm`, 则`subpath`为`jxxx/xytz`
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 西南财经大学
|
||||
|
||||
### 经济信息工程学院
|
||||
|
||||
@@ -2307,4 +2307,7 @@ router.get('/magireco/event_banner', require('./routes/magireco/event_banner'));
|
||||
// wolley
|
||||
router.get('/wolley', require('./routes/wolley/index'));
|
||||
|
||||
// 西安交大
|
||||
router.get('/xjtu/dean/:subpath+', require('./routes/universities/xjtu/dean'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
91
lib/routes/universities/xjtu/dean.js
Normal file
91
lib/routes/universities/xjtu/dean.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const subpath = ctx.params.subpath;
|
||||
|
||||
const url = `http://dean.xjtu.edu.cn/${subpath.replace(/\.htm/g, '')}.htm`;
|
||||
const base = url
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.join('/');
|
||||
|
||||
const list_response = await got.get(url);
|
||||
const $ = cheerio.load(list_response.data);
|
||||
|
||||
const subname = $('em.ma-nav a')
|
||||
.slice(1)
|
||||
.map(function() {
|
||||
return $(this).text();
|
||||
})
|
||||
.get()
|
||||
.join(' - ');
|
||||
|
||||
const list = $('.list_main_content > .list-li').get();
|
||||
|
||||
const parseContent = async (htmlString) => {
|
||||
const $ = cheerio.load(htmlString);
|
||||
|
||||
const info = $('.detail_main_content > h1')
|
||||
.contents()
|
||||
.filter(function() {
|
||||
return this.nodeType === 3;
|
||||
})
|
||||
.map(function() {
|
||||
return $(this)
|
||||
.text()
|
||||
.trim();
|
||||
})
|
||||
.get();
|
||||
|
||||
const content = $('[id^="vsb_content"]');
|
||||
$('form > div > ul a').each(function() {
|
||||
$(this).appendTo(content);
|
||||
$('<br>').appendTo(content);
|
||||
});
|
||||
|
||||
return {
|
||||
author: info[0] || '教务处',
|
||||
description: content.html(),
|
||||
pubDate: new Date(info[1]),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
|
||||
const title = $('a');
|
||||
const link = new URL(title.attr('href'), base);
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const rssitem = {
|
||||
title: title.text().trim(),
|
||||
link: link,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await got.get(link);
|
||||
const result = await parseContent(response.data);
|
||||
|
||||
rssitem.description = result.description;
|
||||
rssitem.author = result.author;
|
||||
rssitem.pubDate = result.pubDate;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
ctx.cache.set(link, JSON.stringify(rssitem));
|
||||
return Promise.resolve(rssitem);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `西安交大教务处 - ${subname}`,
|
||||
link: url,
|
||||
item: out.filter((item) => item !== ''),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user