parent
48e3ca8700
commit
318a5ac453
|
|
@ -3,36 +3,35 @@ const cheerio = require('cheerio');
|
|||
const url = require('url');
|
||||
|
||||
const host = 'http://cse.seu.edu.cn/';
|
||||
const noticHost = 'http://cse.seu.edu.cn/CSE/UI/Notice/';
|
||||
|
||||
const map = new Map([
|
||||
['xyxw', { title: '东南大学计算机技术与工程学院 -- 学院新闻', suffix: 'Notice.aspx?Notice_Type=0' }],
|
||||
['tzgg', { title: '东南大学计算机技术与工程学院 -- 通知公告', suffix: 'Notice.aspx?Notice_Type=1' }],
|
||||
['jwxx', { title: '东南大学计算机技术与工程学院 -- 教务信息', suffix: 'Notice.aspx?Notice_Type=2' }],
|
||||
['jyxx', { title: '东南大学计算机技术与工程学院 -- 就业信息', suffix: 'Notice.aspx?Notice_Type=3' }],
|
||||
['xgsw', { title: '东南大学计算机技术与工程学院 -- 学工事务', suffix: 'Notice.aspx?Notice_Type=4' }],
|
||||
['xyxw', { title: '东南大学计算机技术与工程学院 -- 学院新闻', suffix: '22535/list.htm' }],
|
||||
['tzgg', { title: '东南大学计算机技术与工程学院 -- 通知公告', suffix: '22536/list.htm' }],
|
||||
['jwxx', { title: '东南大学计算机技术与工程学院 -- 教务信息', suffix: '22538/list.htm' }],
|
||||
['jyxx', { title: '东南大学计算机技术与工程学院 -- 就业信息', suffix: '22537/list.htm' }],
|
||||
['xgsw', { title: '东南大学计算机技术与工程学院 -- 学工事务', suffix: '22539/list.htm' }],
|
||||
]);
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type || 'xyxw';
|
||||
const suffix = map.get(type).suffix;
|
||||
|
||||
const link = url.resolve(noticHost, suffix);
|
||||
const link = url.resolve(host, suffix);
|
||||
const response = await axios.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('table.datatable tbody tr')
|
||||
const list = $('table.wp_article_list_table tbody tr td > table > tbody > tr')
|
||||
.slice(0, 10)
|
||||
.map(function() {
|
||||
const info = {
|
||||
title: $(this)
|
||||
.find('td:nth-child(1) a')
|
||||
.find('div.news_title.fl > a')
|
||||
.attr('title'),
|
||||
link: $(this)
|
||||
.find('td:nth-child(1) a')
|
||||
.find('div.news_title.fl > a')
|
||||
.attr('href'),
|
||||
date: $(this)
|
||||
.find('td:nth-child(2) span')
|
||||
.find('div.news_time.fr')
|
||||
.text(),
|
||||
};
|
||||
return info;
|
||||
|
|
@ -43,7 +42,7 @@ module.exports = async (ctx) => {
|
|||
list.map(async (info) => {
|
||||
const title = info.title;
|
||||
const date = info.date;
|
||||
const itemUrl = url.resolve(noticHost, info.link);
|
||||
const itemUrl = url.resolve(host, info.link);
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
|
|
@ -56,7 +55,7 @@ module.exports = async (ctx) => {
|
|||
const single = {
|
||||
title: title,
|
||||
link: itemUrl,
|
||||
description: $('.notice-content-wrapper')
|
||||
description: $('div.wp_articlecontent')
|
||||
.html()
|
||||
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
|
||||
.trim(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue