/
store.ts
61 lines (52 loc) 路 1.5 KB
/
store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
export const route: Route = {
path: '/:store',
categories: ['shopping'],
example: '/shopback/shopee-mart',
parameters: { store: 'Store, can be found in URL' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['shopback.com.tw/:category', 'shopback.com.tw/'],
},
],
name: 'Store',
maintainers: ['nczitzk'],
handler,
};
async function handler(ctx) {
const store = ctx.req.param('store');
const rootUrl = 'https://www.shopback.com.tw';
const currentUrl = `${rootUrl}/${store}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = 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();
return {
title: `${$('h1').text()} - ShopBack`,
link: currentUrl,
item: items,
};
}