feat(route): add ShopBack (#8565)

This commit is contained in:
Ethan Shen 2021-11-27 17:10:03 +08:00 committed by GitHub
parent 3b83b0ec4b
commit 77c15326bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
module.exports = {
'/:store': ['nczitzk'],
};

13
lib/v2/shopback/radar.js Normal file
View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:store', require('./store'));
};

37
lib/v2/shopback/store.js Normal file
View File

@ -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,
};
};