From ecf0bb7a9cd61f1211cf5eb90aa8ef9064236f0b Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 18 Oct 2020 23:24:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BD=E9=98=B2=E7=A7=91=E6=8A=80?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E7=A0=94=E7=A9=B6=E7=94=9F=E6=8B=9B=E7=94=9F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=BD=91=20(#5887)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/university.md | 12 +++++ lib/router.js | 3 ++ lib/routes/universities/nudt/yjszs.js | 66 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 lib/routes/universities/nudt/yjszs.js diff --git a/docs/university.md b/docs/university.md index 3f59b93ea..00aea88cf 100644 --- a/docs/university.md +++ b/docs/university.md @@ -482,6 +482,18 @@ xskb1 对应 +## 国防科技大学 + +### 研究生招生信息网 + + + +| 通知公告 | 招生简章 | 学校政策 | 硕士招生 | 博士招生 | 院所发文 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| 0 | 8 | 12 | 16 | 17 | 23 | + + + ## 哈尔滨工程大学 ### 本科生院工作通知 diff --git a/lib/router.js b/lib/router.js index 94e41663a..ec1b532fd 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/universities/nudt/yjszs.js b/lib/routes/universities/nudt/yjszs.js new file mode 100644 index 000000000..6d717022a --- /dev/null +++ b/lib/routes/universities/nudt/yjszs.js @@ -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, + }; +};