This commit is contained in:
Chenyang Shi
2019-04-08 11:29:11 +08:00
committed by DIYgod
parent ba57ded1cd
commit a9e9ca0b19
3 changed files with 76 additions and 0 deletions

View File

@@ -462,6 +462,10 @@ type 为 all 时category 参数不支持 cost 和 free
<route name="产业研究报告" author="brilon" example="/iresearch/report" path="/iresearch/report"/> <route name="产业研究报告" author="brilon" example="/iresearch/report" path="/iresearch/report"/>
### ZAKER
<Route name="source" author="LogicJake" example="/zaker/source/12291" path="/zaker/source/:id" :paramsDesc="['source id可在 URL 中找到']"/>
### MobData ### MobData
<route name="分析报告" author="brilon" example="/mobdata/report" path="/mobdata/report"/> <route name="分析报告" author="brilon" example="/mobdata/report" path="/mobdata/report"/>

View File

@@ -1227,6 +1227,9 @@ router.get('/checkee/:dispdate', require('./routes/checkee/index'));
// 艾瑞 // 艾瑞
router.get('/iresearch/report', require('./routes/iresearch/report')); router.get('/iresearch/report', require('./routes/iresearch/report'));
// ZAKER
router.get('/zaker/source/:id', require('./routes/zaker/source'));
// Matters // Matters
router.get('/matters/topics', require('./routes/matters/topics')); router.get('/matters/topics', require('./routes/matters/topics'));
router.get('/matters/latest', require('./routes/matters/latest')); router.get('/matters/latest', require('./routes/matters/latest'));

View File

@@ -0,0 +1,69 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const date_util = require('../../utils/date');
module.exports = async (ctx) => {
const id = ctx.params.id;
const link = `http://www.myzaker.com/source/${id}`;
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('a.nav_item_active').text();
const list = $('div.figure.flex-block')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('h2 a')
.attr('title'),
link: $(this)
.find('h2 a')
.attr('href'),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const itemUrl = 'http:' + info.link;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios({
url: itemUrl,
method: 'get',
headers: {
Referer: link,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
},
});
const $ = cheerio.load(response.data);
const description = $('div.article_content div')
.html()
.replace(/data-original/g, `src`);
const date = $('span.time').text();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: date_util(date, 8),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${title}-ZAKER新闻`,
link: link,
item: out,
};
};