feat: add zhaishuyuan (#4368)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
suiyuran
2020-04-02 20:58:55 +08:00
committed by GitHub
parent 06626a51f8
commit 65d45e9c94
4 changed files with 64 additions and 0 deletions

View File

@@ -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: [

View File

@@ -203,6 +203,16 @@ count 的取值范围为 1-12为防止请求次数过多推荐设置为 5
<Route author="LogicJake" example="/p-articles/contributors/朗天" path="/p-articles/contributors/:author" :paramsDesc="['作者 id, 可在作者页面 URL 找到']"/>
## 斋书苑
### 最新章节
<Route author="suiyuran" example="/novel/zhaishuyuan/17858" path="/novel/zhaishuyuan/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到, 例如 `17858`']" radar="1">
举例网址https://www.zhaishuyuan.com/book/17858
</Route>
## 纵横
### 章节

View File

@@ -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'));

View File

@@ -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 };
};