feat: add dekudeals (#2391)

This commit is contained in:
Chenyang Shi
2019-06-13 11:32:38 +08:00
committed by DIYgod
parent bf2bf85b8f
commit 8aed54cd37
3 changed files with 51 additions and 0 deletions
+6
View File
@@ -26,6 +26,12 @@ pageClass: routes
<Route author="monner-henster" example="/a9vg/a9vg" path="/a9vg/a9vg"/>
## dekudeals
### 分类
<Route author="LogicJake" example="/dekudeals/most-wanted" path="/dekudeals/:type" :paramsDesc="['分类名称,可在 URL 中查看']"/>
## GNN.tw 游戏新闻
### GNN.tw 游戏新闻
+3
View File
@@ -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'));
+42
View File
@@ -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 = `<img referrerpolicy="no-referrer" src="${img}">` + '<br>' + price;
const single = {
title,
link,
description,
};
return Promise.resolve(single);
})
.get()
);
ctx.state.data = {
title: `${title}—dekudeals`,
link: link,
item: out,
};
};