-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const url = require('url'); | ||
const host = 'http://www.yzu.edu.cn/'; | ||
|
||
const map = new Map([ | ||
['xxyw', { title: '扬州大学 -- 学校要闻', suffix: 'col/col37745/index.html', id: 37745 }], | ||
['xyxw', { title: '扬州大学 -- 校园新闻', suffix: 'col/col37746/index.html', id: 37746 }], | ||
['xxgg', { title: '扬州大学 -- 信息公告', suffix: 'col/col37747/index.html', id: 37747 }], | ||
['xshd', { title: '扬州大学 -- 学术活动', suffix: 'col/col37748/index.html', id: 37748 }], | ||
['mtyd', { title: '扬州大学 -- 媒体扬大', suffix: 'col/col45661/index.html', id: 45661 }], | ||
]); | ||
|
||
module.exports = async (ctx) => { | ||
const type = ctx.params.type; | ||
const suffix = map.get(type).suffix; | ||
|
||
const link = url.resolve(host, suffix); | ||
const response = await got({ | ||
method: 'post', | ||
url: 'http://www.yzu.edu.cn/module/web/jpage/dataproxy.jsp?startrecord=1&endrecord=10&perpage=10', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
Accept: 'application/xml', | ||
}, | ||
data: `columnid=${map.get(type).id}&unitid=54996`, | ||
}); | ||
const $ = cheerio.load(response.data, { xmlMode: true }); | ||
|
||
const list = $('record') | ||
.slice(0, 10) | ||
.map(function() { | ||
const $$ = cheerio.load($(this).html()); | ||
const info = { | ||
title: $$('a').attr('title'), | ||
link: $$('a').attr('href'), | ||
date: $$('span').text(), | ||
}; | ||
return info; | ||
}) | ||
.get(); | ||
|
||
const out = await Promise.all( | ||
list.map(async (info) => { | ||
const title = info.title; | ||
const date = info.date; | ||
const itemUrl = url.resolve(host, info.link); | ||
|
||
const cache = await ctx.cache.get(itemUrl); | ||
if (cache) { | ||
return Promise.resolve(JSON.parse(cache)); | ||
} | ||
|
||
let description; | ||
if (itemUrl.indexOf('yzu.edu.cn/art') !== -1) { | ||
const response = await got.get(itemUrl); | ||
const $ = cheerio.load(response.data); | ||
description = $('#zoom') | ||
.html() | ||
.replace(/src="\//g, `src="${url.resolve(host, '.')}`) | ||
.trim(); | ||
} else { | ||
description = '站外链接无法抓取全文'; | ||
} | ||
|
||
const single = { | ||
title: title, | ||
link: itemUrl, | ||
description: description, | ||
pubDate: new Date(date).toUTCString(), | ||
}; | ||
ctx.cache.set(itemUrl, JSON.stringify(single)); | ||
return Promise.resolve(single); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: map.get(type).title, | ||
link: link, | ||
description: '扬州大学 RSS', | ||
item: out, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const url = require('url'); | ||
const host = 'http://yjszs.yzu.edu.cn/'; | ||
|
||
const map = new Map([ | ||
['tzgg', { title: '扬州大学研究生招生 -- 通知公告', suffix: 'col/col37091/index.html', id: 37091 }], | ||
['bszs', { title: '扬州大学研究生招生 -- 博士招生', suffix: 'col/col37129/index.html', id: 37129 }], | ||
['sszs', { title: '扬州大学研究生招生 -- 硕士招生', suffix: 'col/col37130/index.html', id: 37130 }], | ||
]); | ||
|
||
module.exports = async (ctx) => { | ||
const type = ctx.params.type; | ||
const suffix = map.get(type).suffix; | ||
|
||
const link = url.resolve(host, suffix); | ||
const response = await got({ | ||
method: 'post', | ||
url: 'http://yjszs.yzu.edu.cn/module/web/jpage/dataproxy.jsp?startrecord=1&endrecord=10&perpage=10', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
Accept: 'application/xml', | ||
}, | ||
data: `columnid=${map.get(type).id}&unitid=54996`, | ||
}); | ||
const $ = cheerio.load(response.data, { xmlMode: true }); | ||
|
||
const list = $('record') | ||
.slice(0, 10) | ||
.map(function() { | ||
const $$ = cheerio.load($(this).html()); | ||
const info = { | ||
title: $$('a').attr('title'), | ||
link: $$('a').attr('href'), | ||
date: $$('span').text(), | ||
}; | ||
return info; | ||
}) | ||
.get(); | ||
|
||
const out = await Promise.all( | ||
list.map(async (info) => { | ||
const title = info.title; | ||
const date = info.date; | ||
const itemUrl = url.resolve(host, info.link); | ||
|
||
const cache = await ctx.cache.get(itemUrl); | ||
if (cache) { | ||
return Promise.resolve(JSON.parse(cache)); | ||
} | ||
|
||
let description; | ||
if (itemUrl.indexOf('yzu.edu.cn/art') !== -1) { | ||
const response = await got.get(itemUrl); | ||
const $ = cheerio.load(response.data); | ||
description = $('#zoom') | ||
.html() | ||
.replace(/src="\//g, `src="${url.resolve(host, '.')}`) | ||
.trim(); | ||
} else { | ||
description = '站外链接无法抓取全文'; | ||
} | ||
|
||
const single = { | ||
title: title, | ||
link: itemUrl, | ||
description: description, | ||
pubDate: new Date(date).toUTCString(), | ||
}; | ||
ctx.cache.set(itemUrl, JSON.stringify(single)); | ||
return Promise.resolve(single); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: map.get(type).title, | ||
link: link, | ||
description: '扬州大学研究生招生 RSS', | ||
item: out, | ||
}; | ||
}; |