diff --git a/docs/en/shopping.md b/docs/en/shopping.md index b8aaa57575..ac409701b4 100644 --- a/docs/en/shopping.md +++ b/docs/en/shopping.md @@ -10,6 +10,12 @@ pageClass: routes +## Guiltfree.pl + +### Onsale + + + ## IKEA ### UK - New Product Release diff --git a/docs/shopping.md b/docs/shopping.md index 813a3c2c0f..d979b08d2d 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -24,6 +24,12 @@ pageClass: routes +## Guiltfree.pl + +### Onsale + + + ## LeBonCoin ### Ads diff --git a/lib/router.js b/lib/router.js index f5cbbe03e7..334ac887ab 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/guiltfree/onsale.js b/lib/routes/guiltfree/onsale.js new file mode 100644 index 0000000000..c425f3d065 --- /dev/null +++ b/lib/routes/guiltfree/onsale.js @@ -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, + }; +};