diff --git a/docs/reading.md b/docs/reading.md index 0d569e9b10..e6d649c6b6 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -123,6 +123,12 @@ pageClass: routes ::: +## 博客来 + +### 新书出版 + + + ## 吹牛部落 ### 栏目 diff --git a/lib/router.js b/lib/router.js index 03c7fb8de9..bfa8538868 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/bookscomtw/newbooks.js b/lib/routes/bookscomtw/newbooks.js new file mode 100644 index 0000000000..8ec4dd6e8c --- /dev/null +++ b/lib/routes/bookscomtw/newbooks.js @@ -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}
${title}
NT$${price}元
${pubInfo}`, + link: link.slice(0, link.indexOf('?')), + author: `${author} / ${publisher}`, + }; + }).get(); + ctx.state.data = { + title: $('title').text(), + link: URL, + item: items + }; +}; +