From e2c4eb7c41a49bfc1bb9e10b85b9805eb42147d2 Mon Sep 17 00:00:00 2001 From: junfengP <840282629@qq.com> Date: Mon, 7 Dec 2020 02:01:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20nuaa=20=E7=A0=94=E7=A9=B6=E7=94=9F?= =?UTF-8?q?=E9=99=A2=20(#6312)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/universities/nuaa/yjsy/yjsy.js | 34 ++++++++--------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/routes/universities/nuaa/yjsy/yjsy.js b/lib/routes/universities/nuaa/yjsy/yjsy.js index 8004c6531..97e8c2bc1 100644 --- a/lib/routes/universities/nuaa/yjsy/yjsy.js +++ b/lib/routes/universities/nuaa/yjsy/yjsy.js @@ -2,7 +2,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); const host = 'http://www.graduate.nuaa.edu.cn/'; -const getCookie = require('../utils/pypasswaf'); +const formatPubDate = require('@/utils/date.js'); const map = { latest: '2146/list.htm', @@ -12,12 +12,12 @@ const map = { xxfw: '2147/list.htm', }; -async function load(link, ctx, gotConfig) { +async function load(link, ctx) { const cache = await ctx.cache.get(link); if (cache) { return cache; } - const response = await got.get(host + link, gotConfig); + const response = await got.get(host + link); const $ = cheerio.load(response.data); const images = $('img'); for (let k = 0; k < images.length; k++) { @@ -29,35 +29,25 @@ async function load(link, ctx, gotConfig) { } module.exports = async (ctx) => { - const cookie = await getCookie(); - - const gotConfig = { - headers: { - cookie, - }, - }; const type = ctx.params.type || 'latest'; - const response = await got( - { - method: 'get', - url: host + map[type], - }, - gotConfig - ); + const response = await got({ + method: 'get', + url: host + map[type], + }); const $ = cheerio.load(response.data); - const list = $('#news_list > tbody > tr > td > table > tbody > tr:nth-child(1)').slice(0, 10).get(); + const list = $('#news_list ul.news_ul > li').slice(0, 10).get(); const process = await Promise.all( list.map(async (item) => { - const a = $(item).find('td:nth-child(2) > a:nth-child(2)'); - const t = $(item).find('td:nth-child(3)'); + const a = $(item).find('a'); + const t = $(item).find('span'); const itemUrl = a.attr('href'); const single = { title: a.text(), link: url.resolve(host, itemUrl), guid: url.resolve(host, itemUrl), - pubDate: t.text().slice(0, 10), + pubDate: formatPubDate(t.text()), }; - const other = await load(itemUrl, ctx, gotConfig); + const other = await load(itemUrl, ctx); return Promise.resolve(Object.assign({}, single, other)); }) );