From 909b0fdf4dbad396e9988ebfc3e023adce822fa5 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Wed, 13 Mar 2019 12:07:30 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E4=BB=8A=E6=97=A5=E7=83=AD=E6=A6=9C=20(#?= =?UTF-8?q?1741)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #1734 --- docs/README.md | 4 ++++ lib/router.js | 3 +++ lib/routes/tophub/index.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 lib/routes/tophub/index.js diff --git a/docs/README.md b/docs/README.md index 2b62b08e83..15eff5886f 100755 --- a/docs/README.md +++ b/docs/README.md @@ -3169,3 +3169,7 @@ type 为 all 时,category 参数不支持 cost 和 free + +### 今日热榜 + + diff --git a/lib/router.js b/lib/router.js index ea02c2d741..695ecfda12 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1145,6 +1145,9 @@ router.get('/blogs/jingwei.link', require('./routes/blogs/jingwei_link')); router.get('/uraaka-joshi', require('./routes/uraaka-joshi/uraaka-joshi')); router.get('/uraaka-joshi/:id', require('./routes/uraaka-joshi/uraaka-joshi-user')); +// 今日热榜 +router.get('/tophub/:id', require('./routes/tophub')); + // 游戏时光 router.get('/vgtime/news', require('./routes/vgtime/news.js')); router.get('/vgtime/release', require('./routes/vgtime/release')); diff --git a/lib/routes/tophub/index.js b/lib/routes/tophub/index.js new file mode 100644 index 0000000000..44dc42ecf6 --- /dev/null +++ b/lib/routes/tophub/index.js @@ -0,0 +1,34 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const link = `https://tophub.today/n/${id}`; + const response = await axios.get(link); + const $ = cheerio.load(response.data); + + const title = $('div.Xc-ec-L.b-L') + .text() + .trim(); + + const out = $('div.Zd-p-Sc > div:nth-child(1) tr') + .map(function() { + const info = { + title: $(this) + .find('td.al a') + .text(), + link: $(this) + .find('td.al a') + .attr('href'), + }; + return info; + }) + .get(); + + ctx.state.data = { + title: title, + link: link, + item: out, + }; +};