From 20b3b59b5a0826f4d231feaa4e9c5fc7f7e61c7e Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Mon, 31 Dec 2018 01:00:20 +0800 Subject: [PATCH] Fix seu (#1323) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #1316 * 计算机技术与工程学院rss正常 * 信息科学与工程学院学术活动最新一期跳转到了微信文章,加了判断 --- lib/routes/universities/seu/radio/academic.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/routes/universities/seu/radio/academic.js b/lib/routes/universities/seu/radio/academic.js index 166192d884..0d76273343 100644 --- a/lib/routes/universities/seu/radio/academic.js +++ b/lib/routes/universities/seu/radio/academic.js @@ -10,14 +10,24 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); - const list = $('.Article_Title a') + const list = $('.list_item') .slice(0, 10) - .map((i, e) => $(e).attr('href')) + .map(function() { + const info = { + link: $(this) + .find('div:nth-child(1) span.Article_Title a') + .attr('href'), + date: $(this) + .find('div:nth-child(2) span') + .text(), + }; + return info; + }) .get(); const out = await Promise.all( - list.map(async (itemUrl) => { - itemUrl = url.resolve(host, itemUrl); + list.map(async (info) => { + const itemUrl = url.resolve(host, info.link); const cache = await ctx.cache.get(itemUrl); if (cache) { return Promise.resolve(JSON.parse(cache)); @@ -26,6 +36,18 @@ module.exports = async (ctx) => { const response = await axios.get(itemUrl); const $ = cheerio.load(response.data); + if (itemUrl.indexOf('redirect') !== -1) { + const single = { + title: $('.rich_media_title') + .text() + .trim(), + link: itemUrl, + description: $('.rich_media_content').text(), + pubDate: new Date(info.date), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + } const single = { title: $('.arti_title').text(), link: itemUrl,