Skip to content

Commit

Permalink
feat: add 东北大学新闻网 (DIYgod#3965)
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer committed Feb 15, 2020
1 parent 63aea3b commit 0c86287
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/university.md
Expand Up @@ -247,6 +247,18 @@ xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm

</Route>

## 东北大学

### 东北大学新闻网

<Route author="JeasonLau" example="/neu/news/ddyw" path="/neu/news/:type" :paramsDesc="['种类名']">

| 东大要闻 | 媒体东大 | 通知公告 | 新闻纵横 | 人才培养 | 学术科研 | 英文新闻 | 招生就业 | 考研出国 | 校园文学 | 校友风采 |
| -------- | -------- | -------- | -------- | -------: | -------- | -------- | -------- | -------- | -------- | -------- |
| ddyw | mtdd | tzgg | xwzh | rcpy | xsky | 217 | zsjy | kycg | xywx | xyfc |

</Route>

## 东莞理工学院

### 教务处通知
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Expand Up @@ -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;
63 changes: 63 additions & 0 deletions 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,
};
};

0 comments on commit 0c86287

Please sign in to comment.