From f83a3c8bf9988827c6f7b2d5c938e3c4b3d97cb2 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Mon, 18 Mar 2019 15:17:36 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E4=BA=B2=E5=AD=90=E7=8E=8B=E5=9B=BD=20(#?= =?UTF-8?q?1769)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 10 ++++++ lib/router.js | 3 ++ lib/routes/babykingdom/index.js | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/routes/babykingdom/index.js diff --git a/docs/README.md b/docs/README.md index d22d7fd0d..f81d94864 100755 --- a/docs/README.md +++ b/docs/README.md @@ -3201,3 +3201,13 @@ type 为 all 时,category 参数不支持 cost 和 free ### 今日热榜 + +### 親子王國 + + + +| 发帖时间 | 回复/查看 | 查看 | 最后发表 | 热门 | +| -------- | --------- | ---- | -------- | ---- | +| dateline | reply | view | lastpost | heat | + + diff --git a/lib/router.js b/lib/router.js index 6e9b52435..9ebbc5483 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1163,6 +1163,9 @@ router.get('/vgtime/release', require('./routes/vgtime/release')); // MP4吧 router.get('/mp4ba/:param', require('./routes/mp4ba')); +// 親子王國 +router.get('/babykingdom/:id/:order?', require('./routes/babykingdom')); + // 浙江工商大学 router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts')); router.get('/zjgsu/gsgg', require('./routes/universities/zjgsu/gsgg/scripts')); diff --git a/lib/routes/babykingdom/index.js b/lib/routes/babykingdom/index.js new file mode 100644 index 000000000..ddb1bd113 --- /dev/null +++ b/lib/routes/babykingdom/index.js @@ -0,0 +1,55 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'https://www.baby-kingdom.com'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + const order = ctx.params.order; + + let link = `https://www.baby-kingdom.com/forum.php?mod=forumdisplay&fid=${id}`; + + if (order === 'dateline') { + link += '&filter=author&orderby=dateline'; + } else if (order === 'reply') { + link += '&filter=reply&orderby=replies'; + } else if (order === 'view') { + link += '&filter=reply&orderby=views'; + } else if (order === 'lastpost') { + link += '&filter=lastpost&orderby=lastpost'; + } else if (order === 'heat') { + link += '&filter=heat&orderby=heats'; + } + + const response = await axios.get(link); + const $ = cheerio.load(response.data); + + const title = $('h1.xs2 a').text(); + const out = $('tbody[id^="normalthread"]') + .slice(0, 10) + .map(function() { + const info = { + title: $(this) + .find('td:nth-child(2) > a:nth-child(1)') + .text(), + link: url.resolve( + host, + $(this) + .find('td:nth-child(2) > a:nth-child(1)') + .attr('href') + ), + author: $(this) + .find('td.by.by_author cite a') + .text(), + }; + return info; + }) + .get(); + + ctx.state.data = { + title: `${title}-親子王國`, + link: link, + item: out, + }; +};