From a9e9ca0b192bfcc9cf6d51b0d5dbc0c6b8cbb4c5 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Mon, 8 Apr 2019 11:29:11 +0800 Subject: [PATCH] add zaker (#1869) --- docs/other.md | 4 +++ lib/router.js | 3 ++ lib/routes/zaker/source.js | 69 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 lib/routes/zaker/source.js diff --git a/docs/other.md b/docs/other.md index 7846a8fed4..dd44626e29 100644 --- a/docs/other.md +++ b/docs/other.md @@ -462,6 +462,10 @@ type 为 all 时,category 参数不支持 cost 和 free +### ZAKER + + + ### MobData diff --git a/lib/router.js b/lib/router.js index 438d5f28c6..72ce34cdad 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1227,6 +1227,9 @@ router.get('/checkee/:dispdate', require('./routes/checkee/index')); // 艾瑞 router.get('/iresearch/report', require('./routes/iresearch/report')); +// ZAKER +router.get('/zaker/source/:id', require('./routes/zaker/source')); + // Matters router.get('/matters/topics', require('./routes/matters/topics')); router.get('/matters/latest', require('./routes/matters/latest')); diff --git a/lib/routes/zaker/source.js b/lib/routes/zaker/source.js new file mode 100644 index 0000000000..6d3be58f24 --- /dev/null +++ b/lib/routes/zaker/source.js @@ -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, + }; +};