From 52f18fc74b9c4c2241713ff7a8cc462ea373e2c5 Mon Sep 17 00:00:00 2001 From: Lao-Liu233 <52364111+Lao-Liu233@users.noreply.github.com> Date: Sat, 27 Nov 2021 16:55:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20fzu=20=E9=80=82=E9=85=8D=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=95=99=E5=8A=A1=E5=A4=84=E7=BD=91=E7=AB=99=20(#8150?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 8 +++++ lib/router.js | 1 + lib/routes/universities/fzu/news.js | 33 +++++++++---------- lib/routes/universities/fzu/news_min.js | 44 +++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 lib/routes/universities/fzu/news_min.js diff --git a/docs/university.md b/docs/university.md index f95cc6efe..108fd832d 100644 --- a/docs/university.md +++ b/docs/university.md @@ -703,6 +703,14 @@ xskb1 对应 | -------- | -------- | | jxtz | zjjz | +### 教务处通知(无文章内容) + + + +| 教学通知 | 专家讲座 | +| -------- | -------- | +| jxtz | zjjz | + ## 复旦大学继续教育学院 ### 成人夜大通知公告 diff --git a/lib/router.js b/lib/router.js index 06247be8f..af924397c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -910,6 +910,7 @@ router.get('/lyu/news/:type', lazyloadRouteHandler('./routes/universities/lyu/ne // 福州大学 router.get('/fzu/:type', lazyloadRouteHandler('./routes/universities/fzu/news')); +router.get('/fzu_min/:type', lazyloadRouteHandler('./routes/universities/fzu/news_min')); // 厦门大学 router.get('/xmu/aero/:type', lazyloadRouteHandler('./routes/universities/xmu/aero')); diff --git a/lib/routes/universities/fzu/news.js b/lib/routes/universities/fzu/news.js index e194e5ce4..244f62dc1 100644 --- a/lib/routes/universities/fzu/news.js +++ b/lib/routes/universities/fzu/news.js @@ -1,14 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const url_map = { - jxtz: '1804', - zjjz: '1809', -}; -const Referer_map = { - jxtz: '/jxtz/', - zjjz: '/zjjz/', -}; const title_map = { jxtz: '教学通知', zjjz: '专家讲座', @@ -22,17 +14,22 @@ module.exports = async (ctx) => { const type = ctx.params.type || ''; const response = await got({ method: 'get', - url: `http://jwch.fzu.edu.cn/plus/json.aspx?jid=J131925584886784703&classid=${url_map[type]}&page=1&column=infoid%2Cclassid%2Ctitle%2Cdefaultpic%2Cintro%2Cadddate%2Curl%2Cclassname`, - headers: { - Referer: `http://jwch.fzu.edu.cn${Referer_map[type]}`, - }, + url: `https://jwch.fzu.edu.cn/${type}.htm`, }); - const data = response.data.data; + const data = response.data; // 获取页面 html 数据 - const urls = new Array(); - for (let i = 0; i <= 9; i++) { - urls[i] = data[i].url; - } + const $ = cheerio.load(data); + const list = $('ul.list-gl'); //
  • s + + const urls = []; + + const url_head = 'https://jwch.fzu.edu.cn/'; + + list.find('a').each(function () { + const a = $(this); + const url_part = a.attr('href'); + urls.push(url_head + url_part); + }); const items = await Promise.all( urls.map((item) => @@ -57,7 +54,7 @@ module.exports = async (ctx) => { ctx.state.data = { title: `福州大学教务处${title_map[type]}`, - link: `http://jwch.fzu.edu.cn/jxtz/`, + link: `http://jwch.fzu.edu.cn/${type}`, description: `福州大学教务处${description_map[type]}`, item: items, }; diff --git a/lib/routes/universities/fzu/news_min.js b/lib/routes/universities/fzu/news_min.js new file mode 100644 index 000000000..41ff8ce5f --- /dev/null +++ b/lib/routes/universities/fzu/news_min.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const title_map = { + jxtz: '教学通知', + zjjz: '专家讲座', +}; +const description_map = { + jxtz: '教学通知', + zjjz: '嘉锡讲坛/信息素养讲座通知', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || ''; + const response = await got({ + method: 'get', + url: `https://jwch.fzu.edu.cn/${type}.htm`, + }); + const data = response.data; // 获取页面 html 数据 + + const $ = cheerio.load(data); + const list = $('ul.list-gl').find('li'); //
  • s + + const url_head = 'https://jwch.fzu.edu.cn/'; + + ctx.state.data = { + title: `福州大学教务处${title_map[type]}`, + link: `http://jwch.fzu.edu.cn/${type}`, + description: `福州大学教务处${description_map[type]}`, + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('a').attr('title'), + discription: item.find('a').attr('title'), + link: url_head + item.find('a').attr('href'), + pubDate: item.find('span').html(), + }; + }) + .get(), + }; +};