From 8aed54cd37171548b62838cdc63344b2d70c5418 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Thu, 13 Jun 2019 11:32:38 +0800 Subject: [PATCH] feat: add dekudeals (#2391) --- docs/game.md | 6 +++++ lib/router.js | 3 +++ lib/routes/dekudeals/index.js | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/routes/dekudeals/index.js diff --git a/docs/game.md b/docs/game.md index 8f01cb01a..7142ffc10 100644 --- a/docs/game.md +++ b/docs/game.md @@ -26,6 +26,12 @@ pageClass: routes +## dekudeals + +### 分类 + + + ## GNN.tw 游戏新闻 ### GNN.tw 游戏新闻 diff --git a/lib/router.js b/lib/router.js index 93f01502a..7cbde0770 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1396,6 +1396,9 @@ router.get('/005tv/zx/latest', require('./routes/005tv/zx')); // Polimi News router.get('/polimi/news/:language?', require('./routes/polimi/news')); +// dekudeals +router.get('/dekudeals/:type', require('./routes/dekudeals')); + // 直播吧 router.get('/zhibo8/forum/:id', require('./routes/zhibo8/forum')); router.get('/zhibo8/post/:id', require('./routes/zhibo8/post')); diff --git a/lib/routes/dekudeals/index.js b/lib/routes/dekudeals/index.js new file mode 100644 index 000000000..3f0929a1b --- /dev/null +++ b/lib/routes/dekudeals/index.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'https://www.dekudeals.com/'; +module.exports = async (ctx) => { + const type = ctx.params.type; + const link = url.resolve(host, type); + + const response = await got.get(link); + const $ = cheerio.load(response.data); + + const title = $('body > main > div:nth-child(1) > div > h3').text(); + const list = $('body > main > div:nth-child(2) > div > table > tbody > tr'); + + const out = await Promise.all( + list + .map(async (index, item) => { + item = $(item); + const title = item.find('td:nth-child(2) > a').text(); + const link = url.resolve(host, item.find('td:nth-child(2) > a').attr('href')); + const img = item.find('td.image img').attr('src'); + const price = item.find('td:nth-child(3)').html(); + const description = `` + '
' + price; + + const single = { + title, + link, + description, + }; + + return Promise.resolve(single); + }) + .get() + ); + + ctx.state.data = { + title: `${title}—dekudeals`, + link: link, + item: out, + }; +};