diff --git a/assets/radar-rules.js b/assets/radar-rules.js index ee9ca1dbaf..c7bad6a443 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -1549,6 +1549,17 @@ }, ], }, + 'zhaishuyuan.com': { + _name: '斋书苑', + www: [ + { + title: '最新章节', + docs: 'https://docs.rsshub.app/reading.html#zhai-shu-yuan', + source: ['/book/:id', '/read/:id'], + target: '/novel/zhaishuyuan/:id', + }, + ], + }, 'hbut.edu.cn': { _name: '湖北工业大学', www: [ diff --git a/docs/reading.md b/docs/reading.md index 2408223fdf..0fc7d1dd86 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -203,6 +203,16 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 +## 斋书苑 + +### 最新章节 + + + +举例网址:https://www.zhaishuyuan.com/book/17858 + + + ## 纵横 ### 章节 diff --git a/lib/router.js b/lib/router.js index 9a2853853b..5d85af1647 100644 --- a/lib/router.js +++ b/lib/router.js @@ -522,6 +522,7 @@ router.get('/novel/wenxuemi/:id1/:id2', require('./routes/novel/wenxuemi')); router.get('/novel/booksky/:id', require('./routes/novel/booksky')); router.get('/novel/shuquge/:id', require('./routes/novel/shuquge')); router.get('/novel/ptwxz/:id1/:id2', require('./routes/novel/ptwxz')); +router.get('/novel/zhaishuyuan/:id', require('./routes/novel/zhaishuyuan')); // 中国气象网 router.get('/weatheralarm', require('./routes/weatheralarm')); diff --git a/lib/routes/novel/zhaishuyuan.js b/lib/routes/novel/zhaishuyuan.js new file mode 100644 index 0000000000..72efaaad1b --- /dev/null +++ b/lib/routes/novel/zhaishuyuan.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const url = 'https://www.zhaishuyuan.com'; + const link = `${url}/book/${id}`; + let extendedGot = got.extend({ headers: { Referer: url }, responseType: 'buffer' }); + const response = await extendedGot.get(link); + const html = iconv.decode(response.data, 'gb2312'); + const $ = cheerio.load(html); + const title = $('.booktitle > h1').text(); + const description = $('#bookintro > p').text(); + const image = $('#bookimg > img').attr('src'); + const list = $('#newlist > ul > li') + .find('a') + .map((_, { attribs: { title, href } }) => ({ title, link: `${url}${href}` })) + .get(); + extendedGot = got.extend({ headers: { Referer: link }, responseType: 'buffer' }); + const item = await Promise.all( + list.map( + async ({ title, link }) => + await ctx.cache.tryGet(link, async () => { + const response = await extendedGot.get(link); + const html = iconv.decode(response.data, 'gb2312'); + const $ = cheerio.load(html); + const content = $('#content'); + content.find('div').remove(); + const description = content.html(); + const spanList = $('.title > span'); + const author = spanList + .eq(0) + .find('a') + .text(); + const pubDate = spanList.eq(2).text(); + return { title, link, description, author, pubDate }; + }) + ) + ); + ctx.state.data = { title, link, description, image, item }; +};