feat: add guiltfree onsale (#5517)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-08-29 05:00:12 +08:00
committed by GitHub
parent a1690a9e86
commit d80582d392
4 changed files with 64 additions and 0 deletions

View File

@@ -10,6 +10,12 @@ pageClass: routes
<RouteEn author="luyuhuang" example="/alter-cn/news" path="/alter-cn/news"/>
## Guiltfree.pl
### Onsale
<RouteEn author="nczitzk" example="/guiltfree/onsale" path="/guiltfree/onsale"/>
## IKEA
### UK - New Product Release

View File

@@ -24,6 +24,12 @@ pageClass: routes
<Route author="NeverBehave" example="/furstar/artists/cn" path="/furstar/artists/:lang?" :paramsDesc="['语言, 留空为jp, 支持cn, en']"/>
## Guiltfree.pl
### Onsale
<Route author="nczitzk" example="/guiltfree/onsale" path="/guiltfree/onsale"/>
## LeBonCoin
### Ads

View File

@@ -3119,6 +3119,9 @@ router.get('/fjnews/fz/30', require('./routes/fjnews/fznews'));
// 九江新闻jjnews
router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews'));
// Guiltfree
router.get('/guiltfree/onsale', require('./routes/guiltfree/onsale'));
// 消费明鉴
router.get('/mingjian', require('./routes/mingjian/index'));

View File

@@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = 'https://www.guiltfree.pl/pl/onsale';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('#prodlistx ul li')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('a.product-name');
return {
title: item.find('span.name_list').text(),
link: a.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.cartqtyrow').remove();
content('#accessoriesblock').remove();
content('#crossselling_block').remove();
item.description = content('#center_column').html();
return item;
})
)
);
ctx.state.data = {
title: 'Guiltfree.pl - Wyprzedaże',
link: currentUrl,
item: items,
};
};