From fb82a648a48e117dcd2cdf9d546204f2e3de49e5 Mon Sep 17 00:00:00 2001 From: bot_3310 Date: Sun, 3 Jun 2018 00:33:47 +0800 Subject: [PATCH] rss:add uukanshu.com (#258) * add uukansu rss --- README.md | 2 ++ docs/README.md | 10 ++++++++++ router.js | 3 +++ routes/uukanshu/chapter.js | 41 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 routes/uukanshu/chapter.js diff --git a/README.md b/README.md index adb0c3772..a75a264c2 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - Popular Recent Posts - 纽约时报 - 新闻早报 +- UU 看书 + - 小说章节 ## 鸣谢 diff --git a/docs/README.md b/docs/README.md index 6ab53b3ca..9c79a7c5a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 中找到 diff --git a/router.js b/router.js index 685011741..c6f4ae613 100644 --- a/router.js +++ b/router.js @@ -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; diff --git a/routes/uukanshu/chapter.js b/routes/uukanshu/chapter.js new file mode 100644 index 000000000..16d68add8 --- /dev/null +++ b/routes/uukanshu/chapter.js @@ -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, + }; +};