fix #1316 
* 计算机技术与工程学院rss正常
* 信息科学与工程学院学术活动最新一期跳转到了微信文章,加了判断
This commit is contained in:
Chenyang Shi
2018-12-31 01:00:20 +08:00
committed by DIYgod
parent 668161fe5d
commit 20b3b59b5a
+26 -4
View File
@@ -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,