From 37071454284ff20ba70d28bf2c0aced54193708f Mon Sep 17 00:00:00 2001 From: fengkx Date: Sun, 14 Oct 2018 16:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=BB=AD=20RSS=20(#872)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加 puppeteer 依赖 * houxu --- docs/README.md | 4 ++++ router.js | 3 +++ routes/houxu/houxu.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 routes/houxu/houxu.js diff --git a/docs/README.md b/docs/README.md index 47224eb6f..f239f10be 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1851,3 +1851,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 ### 观止(每日一文) + +### 后续 + + diff --git a/router.js b/router.js index 33c826146..f9b055b51 100644 --- a/router.js +++ b/router.js @@ -625,6 +625,9 @@ router.get('/pediy/topic/:category?/:type?', require('./routes/pediy/topic')); // 观止(每日一文) router.get('/guanzhi', require('./routes/guanzhi/guanzhi')); +// 后续 +router.get('/houxu/:type/:id', require('./routes/houxu/houxu')); + // 老司机 router.get('/laosiji/hot', require('./routes/laosiji/hot')); router.get('/laosiji/feed', require('./routes/laosiji/feed')); diff --git a/routes/houxu/houxu.js b/routes/houxu/houxu.js new file mode 100644 index 000000000..4996df5ff --- /dev/null +++ b/routes/houxu/houxu.js @@ -0,0 +1,35 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { type, id } = ctx.params; + const baseUrl = `https://houxu.app/${type}/${id}`; + const res = await axios.get(baseUrl); + const data = res.data; + const $ = cheerio.load(data); + + const list = $('section.threads > div').get(); + const descriptionSelector = type === 'live' ? '.summary' : '.readable'; + const out = list.map((item) => { + const each = $(item); + return { + title: each + .find('a') + .text() + .trim(), + description: each + .find(descriptionSelector) + .text() + .trim(), + link: each.find('a').attr('href'), + }; + }); + ctx.state.data = { + title: $('.large-title').text(), + description: $('title') + .text() + .trim(), + link: baseUrl, + item: out, + }; +};