mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): add 博客来网路书店 (#6969)
Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
@@ -123,6 +123,12 @@ pageClass: routes
|
||||
|
||||
:::
|
||||
|
||||
## 博客来
|
||||
|
||||
### 新书出版
|
||||
|
||||
<Route author="CokeMine" example="/bookscomtw/newbooks/books_nbtopm_15" path="/bookscomtw/newbooks/:category" :paramsDesc="['书籍类型 category, 可在对应博客来新书页 URL 中找到']"/>
|
||||
|
||||
## 吹牛部落
|
||||
|
||||
### 栏目
|
||||
|
||||
@@ -3982,6 +3982,9 @@ router.get('/iyiou', require('./routes/iyiou'));
|
||||
// 香港商报
|
||||
router.get('/hkcd/pdf', require('./routes/hkcd/pdf'));
|
||||
|
||||
// 博客来
|
||||
router.get('/bookscomtw/newbooks/:category', require('./routes/bookscomtw/newbooks'));
|
||||
|
||||
// Elite Babes
|
||||
router.get('/elitebabes/videos/:sort?', require('./routes/elitebabes/videos'));
|
||||
router.get('/elitebabes/search/:keyword?', require('./routes/elitebabes/search'));
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
module.exports = async (ctx) => {
|
||||
const URL = `https://www.books.com.tw/web/${ctx.params.category}/`;
|
||||
const {data} = await got({
|
||||
method: 'get',
|
||||
url: URL
|
||||
});
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('div.mod_a div.wrap div.item');
|
||||
const items = list.map((i, item) => {
|
||||
item = $(item);
|
||||
const title = item.find('h4').text().trim();
|
||||
let imgLink = item.find('a img.cover').attr('src').trim();
|
||||
imgLink = imgLink.slice(imgLink.indexOf('https', 1), imgLink.indexOf('.jpg') + 4);
|
||||
const link = item.find('a').attr('href');
|
||||
const desc = item.find('div.txt_cont p').text().trim();
|
||||
const author = item.find('li.info>a').text();
|
||||
const publisher = item.find('li.info span>a').text();
|
||||
const pubInfo = item.find('li.info').text();
|
||||
let price = item.find('ul.price li.set2 strong');
|
||||
price = price.length === 1 ? parseInt(price.text().trim()) :
|
||||
parseInt(price.eq(0).text() > 10 ? (price.eq(1).text() * 100 / price.eq(0).text()).toFixed() :
|
||||
(price.eq(1).text() * 10 / price.eq(0).text()).toFixed());
|
||||
return {
|
||||
title,
|
||||
description: `${desc}<br><img src="${imgLink}" alt="${title}"><br>NT$${price}元<br>${pubInfo}`,
|
||||
link: link.slice(0, link.indexOf('?')),
|
||||
author: `${author} / ${publisher}`,
|
||||
};
|
||||
}).get();
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: URL,
|
||||
item: items
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user