Skip to content

Commit

Permalink
feat(route): add ShopBack (DIYgod#8565)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Nov 27, 2021
1 parent 3b83b0e commit 77c1532
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ All brands, see [Brand list](https://www.mercari.com/jp/brand/)

</RouteEn>

## ShopBack

### Store

<RouteEn author="nczitzk" example="/shopback/shopee-mart" path="/shopback/:store" :paramsDesc="['Store, can be found in URL']"/>

## The Independent

### PS5 stock UK
Expand Down
6 changes: 6 additions & 0 deletions docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa

</Route>

## ShopBack

### Store

<Route author="nczitzk" example="/shopback/shopee-mart" path="/shopback/:store" :paramsDesc="['店铺名,可在 URL 中找到']"/>

## The Independent

### PS5 stock UK
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/shopback/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:store': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/shopback/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'shopback.com.tw': {
_name: 'ShopBack',
'.': [
{
title: 'Store',
docs: 'https://docs.rsshub.app/shopping.html#shopback-store',
source: ['/:category', '/'],
target: '/shopback/:store',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/shopback/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:store', require('./store'));
};
37 changes: 37 additions & 0 deletions lib/v2/shopback/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const store = ctx.params.store;

const rootUrl = 'https://www.shopback.com.tw';
const currentUrl = `${rootUrl}/${store}`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

$('table').remove();

const items = $('div[data-content-name]')
.map((_, item) => {
item = $(item);

return {
title: item.attr('data-content-name'),
author: item.attr('data-content-merchant'),
description: `<p>${item.find('.mb-3').text()}</p>`,
link: `${rootUrl}/login?redirect=/redirect/alink/${item.attr('data-content-id')}`,
};
})
.get();

ctx.state.data = {
title: `${$('h1').text()} - ShopBack`,
link: currentUrl,
item: items,
};
};

0 comments on commit 77c1532

Please sign in to comment.