feat: 国防科技大学研究生招生信息网 (#5887)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen 2020-10-18 23:24:01 +08:00 committed by GitHub
parent 56dc1d2a85
commit ecf0bb7a9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 0 deletions

View File

@ -482,6 +482,18 @@ xskb1 对应 <http://www.auto.uestc.edu.cn/index/xskb1.htm>
</Route>
## 国防科技大学
### 研究生招生信息网
<Route author="nczitzk" example="/nudt/yjszs/16" path="/nudt/yjszs/:id?" :paramsDesc="['分类 id默认为 `0` 即通知公告']">
| 通知公告 | 招生简章 | 学校政策 | 硕士招生 | 博士招生 | 院所发文 |
| -------- | -------- | -------- | -------- | -------- | -------- |
| 0 | 8 | 12 | 16 | 17 | 23 |
</Route>
## 哈尔滨工程大学
### 本科生院工作通知

View File

@ -3347,6 +3347,9 @@ router.get('/yuanshen/:location?/:category?', require('./routes/yuanshen/index')
// World Trade Organization
router.get('/wto/dispute-settlement/:year?', require('./routes/wto/dispute-settlement'));
// 国防科技大学
router.get('/nudt/yjszs/:id?', require('./routes/universities/nudt/yjszs'));
// 全现在
router.get('/allnow/column/:id', require('./routes/allnow/column'));

View File

@ -0,0 +1,66 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
ctx.params.id = ctx.params.id || '0';
let currentUrl;
const rootUrl = 'http://yjszs.nudt.edu.cn/';
if (ctx.params.id === '0') {
currentUrl = `${rootUrl}/pubweb/homePageList/searchContent.view`;
} else {
currentUrl = `${rootUrl}/pubweb/homePageList/recruitStudents.view?keyId=${ctx.params.id}`;
}
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('div.info').remove();
const list = $('div.news-list ul li a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.title = content('h1').text();
item.pubDate = new Date(content('p.time').eq(0).text() + ' GMT+8').toUTCString();
content('h1').remove();
content('div.time-browse').remove();
item.description = content('div.content').html();
return item;
})
)
);
let title = $('h2').text();
title = title || '通知公告';
ctx.state.data = {
title: `${title} - 国防科技大学研究生招生信息网`,
link: currentUrl,
item: items,
};
};