commit
c71b3c604c
|
|
@ -36,6 +36,12 @@ Parameter `time` only works when `mostwanted` is chosen as the category.
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## booth.pm
|
||||
|
||||
### Shop
|
||||
|
||||
<Route author="KTachibanaM" example="/booth.pm/shop/annn-boc0123" path="/booth.pm/shop/:subdomain" :paramsDesc="['Shop subdomain']" />
|
||||
|
||||
## Guiltfree.pl
|
||||
|
||||
### Onsale
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## booth.pm
|
||||
|
||||
### 店铺
|
||||
|
||||
<Route author="KTachibanaM" example="/booth.pm/shop/annn-boc0123" path="/booth.pm/shop/:subdomain" :paramsDesc="['店铺子域名']" />
|
||||
|
||||
## Craigslist
|
||||
|
||||
### 商品搜索
|
||||
|
|
|
|||
|
|
@ -3820,4 +3820,7 @@ router.get('/simpread/changelog', require('./routes/simpread/changelog'));
|
|||
// Radio Free Asia
|
||||
router.get('/rfa/:language?/:channel?/:subChannel?', require('./routes/rfa/index'));
|
||||
|
||||
// booth.pm
|
||||
router.get('/booth.pm/shop/:subdomain', require('./routes/booth-pm/shop'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const maxPages = 5;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { subdomain } = ctx.params;
|
||||
const shopUrl = `https://${subdomain}.booth.pm`;
|
||||
|
||||
let shopName;
|
||||
const items = [];
|
||||
for (let page = 1; page <= maxPages; page++) {
|
||||
const pageUrl = `${shopUrl}/items?page=${page}`;
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: pageUrl,
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
shopName = $('div.shop-name > span').text();
|
||||
const pageItems = $('li.item');
|
||||
|
||||
if (pageItems.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (let i = 0; i < pageItems.length; ++i) {
|
||||
const pageItem = pageItems[i];
|
||||
|
||||
// extract item name
|
||||
const itemName = $('h2.item-name > a', pageItem).text();
|
||||
|
||||
// extract item url
|
||||
const itemUrl = shopUrl + $('h2.item-name > a', pageItem).attr('href');
|
||||
|
||||
// extract item preview url
|
||||
const itemPreviewUrl = $('div.swap-image > img', pageItem).attr('src');
|
||||
|
||||
items.push({
|
||||
title: itemName,
|
||||
description: `<img src='${itemPreviewUrl}'/>`,
|
||||
link: itemUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: shopName,
|
||||
link: shopUrl,
|
||||
description: shopName,
|
||||
allowEmpty: true,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue