From 0c862876a54bd11df2912f6002d820d003b03cc3 Mon Sep 17 00:00:00 2001 From: Jeason Lau Date: Sat, 15 Feb 2020 19:13:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=9C=E5=8C=97=E5=A4=A7?= =?UTF-8?q?=E5=AD=A6=E6=96=B0=E9=97=BB=E7=BD=91=20(#3965)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 12 ++++++ lib/router.js | 3 ++ lib/routes/universities/neu/news.js | 63 +++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 lib/routes/universities/neu/news.js diff --git a/docs/university.md b/docs/university.md index be0e712340..f57597a17c 100644 --- a/docs/university.md +++ b/docs/university.md @@ -247,6 +247,18 @@ xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm +## 东北大学 + +### 东北大学新闻网 + + + +| 东大要闻 | 媒体东大 | 通知公告 | 新闻纵横 | 人才培养 | 学术科研 | 英文新闻 | 招生就业 | 考研出国 | 校园文学 | 校友风采 | +| -------- | -------- | -------- | -------- | -------: | -------- | -------- | -------- | -------- | -------- | -------- | +| ddyw | mtdd | tzgg | xwzh | rcpy | xsky | 217 | zsjy | kycg | xywx | xyfc | + + + ## 东莞理工学院 ### 教务处通知 diff --git a/lib/router.js b/lib/router.js index 49fd03ac15..e0df2518b2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2232,4 +2232,7 @@ router.get('/2048/bbs/:fid', require('./routes/2048/bbs')); // Google News router.get('/google/news/:category/:locale', require('./routes/google/news')); +// 东北大学 +router.get('/neu/news/:type', require('./routes/universities/neu/news')); + module.exports = router; diff --git a/lib/routes/universities/neu/news.js b/lib/routes/universities/neu/news.js new file mode 100644 index 0000000000..ee4db7854b --- /dev/null +++ b/lib/routes/universities/neu/news.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const baseUrl = 'http://neunews.neu.edu.cn'; +module.exports = async (ctx) => { + const type = ctx.params.type; + const newsUrl = `${baseUrl}/${type}/list.htm`; + const response = await got({ + method: 'get', + url: newsUrl, + }); + + const data = response.data; + const $ = cheerio.load(data); + + const title = $('title').text(); + const items = $('.column-news-list > .news_list > .news > .news_title') + .slice(0, 10) + .children(); + const results = []; + items.each(async (index, item) => { + const label = $(item); + const title = $(label).attr('title'); + const url = baseUrl + $(label).attr('href'); + const description = await ctx.cache.tryGet(url, async () => { + const result = await got.get(url); + const $ = cheerio.load(result.data); + // 处理部分格式 + $('article') + .find('span') + .each(function() { + const temp = $(this).text(); + $(this).replaceWith(temp); + }); + $('article') + .find('div') + .each(function() { + const temp = $(this).html(); + $(this).replaceWith(temp); + }); + $('article') + .find('a') + .remove(); + $('article') + .find('p') + .each(function() { + $(this).removeAttr('style'); + $(this).removeAttr('class'); + }); + return $('article').html(); + }); + const result = { + title: title, + description: description, + link: url, + }; + results.push(result); + }); + ctx.state.data = { + title: title, + item: results, + }; +};