修复懂球帝早报部分链接 404 的问题 (#1498)

* 修复懂球帝早报部分链接 404 的问题

* refactor: revert back to axios
This commit is contained in:
Henry Wang 2019-02-13 04:16:04 +00:00 committed by DIYgod
parent fd70841e63
commit 8080038e01
1 changed files with 20 additions and 10 deletions

View File

@ -1,6 +1,7 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const utils = require('./utils');
const date = require('../../utils/date');
module.exports = async (ctx) => {
const response = await axios.get('https://www.dongqiudi.com/special/48');
@ -10,7 +11,7 @@ module.exports = async (ctx) => {
const host = 'https://www.dongqiudi.com';
const list = $('.detail.special ul li h3')
.slice(0, 10)
.slice(0, 5)
.get();
const proList = [];
@ -21,18 +22,19 @@ module.exports = async (ctx) => {
const title = $('a').text();
const itemUrl = host + $('a').attr('href');
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title,
link: itemUrl,
};
try {
const es = axios.get(itemUrl);
proList.push(es);
return Promise.resolve(single);
} catch (err) {
console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`);
}
const es = axios.get(itemUrl);
proList.push(es);
return Promise.resolve(single);
})
);
@ -43,11 +45,19 @@ module.exports = async (ctx) => {
out[i].description = utils.ProcessHref(full.find('div:nth-of-type(1)')).html();
out[i].author = full.find('span.name').text();
out[i].pubDate = new Date(full.find('span.time').text()).toUTCString();
out[i].pubDate = date(
full
.find('span.time')
.text()
.trim(),
8
);
ctx.cache.set(out[i].itemUrl, JSON.stringify(out[i]), 24 * 60 * 60);
}
ctx.state.data = {
title: '懂球帝早报',
link: 'http://www.dongqiudi.com/special/48',
item: out,
item: out.filter((e) => e !== undefined),
};
};