mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 07:12:51 +08:00
feat: add 稻草人书屋 (#4019)
This commit is contained in:
@@ -82,6 +82,19 @@ pageClass: routes
|
|||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
## 稻草人书屋
|
||||||
|
|
||||||
|
### 章节更新
|
||||||
|
|
||||||
|
<Route author="JeasonLau" example="/dcrsw/zhongjidouluo/2" path="/dcrsw/:name/:count?" :paramsDesc="['小说名,可在对应小说页URL中找到', '显示的章节数,缺省为`3`']">
|
||||||
|
|
||||||
|
::: warning 注意
|
||||||
|
|
||||||
|
count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 以下。
|
||||||
|
:::
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## 飞地
|
## 飞地
|
||||||
|
|
||||||
### 分类
|
### 分类
|
||||||
|
|||||||
@@ -2259,4 +2259,7 @@ router.get('/haohaozhu/discover/:keyword?', require('./routes/haohaozhu/discover
|
|||||||
// 东北大学
|
// 东北大学
|
||||||
router.get('/neu/news/:type', require('./routes/universities/neu/news'));
|
router.get('/neu/news/:type', require('./routes/universities/neu/news'));
|
||||||
|
|
||||||
|
// 稻草人书屋
|
||||||
|
router.get('/dcrsw/:name/:count?', require('./routes/novel/dcrsw'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
50
lib/routes/novel/dcrsw.js
Normal file
50
lib/routes/novel/dcrsw.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
const baseUrl = 'https://www.daocaorenshuwu.com/book';
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const name = ctx.params.name;
|
||||||
|
const count = ctx.params.count || 3;
|
||||||
|
const novelUrl = `${baseUrl}/${name}`;
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: novelUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = response.data;
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
|
||||||
|
const title = $('h1.book-name')
|
||||||
|
.children()
|
||||||
|
.text();
|
||||||
|
const description = $('div.book-detail').text();
|
||||||
|
const chapters = $('.col-md-6')
|
||||||
|
.slice(0, count)
|
||||||
|
.get();
|
||||||
|
const results = await Promise.all(
|
||||||
|
chapters.map(async (item) => {
|
||||||
|
const $ = cheerio.load(item);
|
||||||
|
|
||||||
|
const chapterTitle = $('a').text();
|
||||||
|
const chapterUrl = 'https:' + $('a').attr('href');
|
||||||
|
const chapterContent = await ctx.cache.tryGet(chapterUrl, async () => {
|
||||||
|
const chapter = await got.get(chapterUrl);
|
||||||
|
const $ = cheerio.load(chapter.data);
|
||||||
|
$('div.cont-text > script').remove();
|
||||||
|
return $('div.cont-text').html();
|
||||||
|
});
|
||||||
|
return Promise.resolve({
|
||||||
|
title: chapterTitle,
|
||||||
|
link: chapterUrl,
|
||||||
|
description: chapterContent,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `稻草人书屋-${title}`,
|
||||||
|
description: description,
|
||||||
|
link: novelUrl,
|
||||||
|
item: results,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user