Skip to content

Commit

Permalink
rss:add uukanshu.com (DIYgod#258)
Browse files Browse the repository at this point in the history
* add uukansu rss
  • Loading branch information
bott0n authored and DIYgod committed Jun 2, 2018
1 parent 09a616d commit fb82a64
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- Popular Recent Posts
- 纽约时报
- 新闻早报
- UU 看书
- 小说章节

## 鸣谢

Expand Down
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,13 @@ language,语言,可在 [Trending 页](https://github.com/trending/javascript
路由: `/nytimes/morning_post`

参数: 无

## UU 看书

### 小说章节

举例: [https://rsshub.app/uukanshu/chapter/49621](https://rsshub.app/uukanshu/chapter/49621)

路由: `/uukanshu/chapter/:id`

参数: id,小说 id,可在对应小说页 URL 中找到
3 changes: 3 additions & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,7 @@ router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/p
// nytimes
router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post'));

// uukanshu
router.get('/uukanshu/chapter/:uid', require('./routes/uukanshu/chapter'));

module.exports = router;
41 changes: 41 additions & 0 deletions routes/uukanshu/chapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
const iconv = require('iconv-lite');

module.exports = async (ctx) => {
const uid = ctx.params.uid;

const response = await axios({
method: 'post',
url: `https://www.uukanshu.com/b/${uid}`,
headers: {
'User-Agent': config.ua,
Referer: 'https://www.uukanshu.com/b/${uid}',
},
responseType: 'arraybuffer',
});

const data = iconv.decode(response.data, 'gb2312');
const $ = cheerio.load(data);

const name = $('.jieshao_content>h1>a').text();
const list = $('#chapterList li a');
const cover_url = $('.bookImg>img').attr('src');
const chapter_item = [];
for (let i = 0; i < list.length; i++) {
const el = $(list[i]);
const item = {
title: el.text(),
link: `https://www.uukanshu.com${el.attr('href')}`,
};
chapter_item.push(item);
}
ctx.state.data = {
title: `UU看书 ${name}`,
link: `https://www.uukanshu.com/b/${uid}`,
description: $('.jieshao_content h3').text(),
image: cover_url,
item: chapter_item,
};
};

0 comments on commit fb82a64

Please sign in to comment.