diff --git a/lib/routes/universities/njfu/jwc.js b/lib/routes/universities/njfu/jwc.js index 4c7df9d17..e30553162 100644 --- a/lib/routes/universities/njfu/jwc.js +++ b/lib/routes/universities/njfu/jwc.js @@ -1,7 +1,8 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const url = 'http://jwc.njfu.edu.cn//sy/'; +const url = 'http://jwc.njfu.edu.cn/sy/'; +let link = ''; const map = { xjfw: '校级发文', tzgg: '通知公告', @@ -10,26 +11,35 @@ const map = { }; module.exports = async (ctx) => { - const category = map.hasOwnProperty(ctx.params.category) ? ctx.params.category : 'tzgg'; - let response; + const category = ctx.params.category ?? 'tzgg'; if (category === 'xzzq') { - response = await got({ - method: 'get', - url: 'http://jwc.njfu.edu.cn//xzzq/index.html', - }); + link = 'http://jwc.njfu.edu.cn/xzzq/'; } else { - response = await got({ - method: 'get', - url: url + category + '/index.html', - }); + link = `${url}${category}/`; } + + const response = await got(link, { + method: 'get', + hooks: { + beforeRedirect: [ + (options, response) => { + const cookie = response.headers['set-cookie']; + if (cookie) { + const cook = cookie.map((c) => c.split(';')[0]).join('; '); + options.headers.Cookie = cook; + options.headers.Referer = response.url; + } + }, + ], + }, + }); const $ = cheerio.load(response.data); const list = $('.List_R4'); ctx.state.data = { title: '南京林业大学教务处-' + map[category], - link: url + category + '/index.html', - description: '南京林业大学教务处-' + map[category] + 'Rss源', + link, + description: `南京林业大学教务处-${map[category]}`, item: list .map((index, item) => ({ title: $(item).find('a').attr('title'),