From efefa241e22b09aab9283cf8e737b7f2f48356d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Tue, 4 Dec 2018 14:24:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E8=99=8E=E5=97=85-?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=20(#1224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1221 --- docs/README.md | 4 ++++ router.js | 3 +++ routes/huxiu/tag.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 routes/huxiu/tag.js diff --git a/docs/README.md b/docs/README.md index 0e92b6571..4d71bd77c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2500,3 +2500,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 + +### 虎嗅 + + diff --git a/router.js b/router.js index 7118bd649..7044d524b 100644 --- a/router.js +++ b/router.js @@ -890,4 +890,7 @@ router.get('/cpu/yjsy', require('./routes/cpu/yjsy')); // 字幕组 router.get('/zimuzu/resource/:id', require('./routes/zimuzu/resource')); +// 虎嗅 +router.get('/huxiu/tag/:id', require('./routes/huxiu/tag')); + module.exports = router; diff --git a/routes/huxiu/tag.js b/routes/huxiu/tag.js new file mode 100644 index 000000000..9020fcbc1 --- /dev/null +++ b/routes/huxiu/tag.js @@ -0,0 +1,40 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const url = `https://www.huxiu.com/tags/${id}.html`; + const response = await axios({ + method: 'get', + url, + headers: { + Referer: url, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.related-article li') + .map((index, elem) => { + const $elem = $(elem); + const $link = $elem.find('a'); + const title = $link.text(); + const time = $elem.find('.time').text(); + const link = $link.attr('href'); + + return { + title, + link: `https://www.huxiu.com${link}`, + description: title, + pubDate: new Date(time).toUTCString(), + }; + }) + .get(); + + ctx.state.data = { + title: `虎嗅-${$('.tag-title').text()}`, + link: url, + description: $('meta[name="description"]').attr('content'), + item: list, + }; +};