forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add ShopBack (DIYgod#8565)
- Loading branch information
Ethan Shen
authored
Nov 27, 2021
1 parent
3b83b0e
commit 77c1532
Showing
6 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/:store': ['nczitzk'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function (router) { | ||
router.get('/:store', require('./store')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |