From 6138bbc9c1291c0eeb2f3933bd657e4e0e7bf29f Mon Sep 17 00:00:00 2001 From: LJason Date: Fri, 17 Jan 2020 10:50:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=B0=8F=E8=AF=B4-?= =?UTF-8?q?=E9=A3=98=E5=A4=A9=E6=96=87=E5=AD=A6=20(#3765)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/reading.md | 10 +++++++++ lib/router.js | 1 + lib/routes/novel/ptwxz.js | 47 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/routes/novel/ptwxz.js diff --git a/docs/reading.md b/docs/reading.md index 6b38aeb78..4c6076630 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -106,6 +106,16 @@ pageClass: routes +## 飘天文学 + +### 章节 + + + +举例网址:https://www.ptwxz.com/bookinfo/10/10272.html + + + ## 起点 ### 章节 diff --git a/lib/router.js b/lib/router.js index 647f76b2f..086dde1d6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -518,6 +518,7 @@ router.get('/novel/uukanshu/:uid', require('./routes/novel/uukanshu')); 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('/weatheralarm', require('./routes/weatheralarm')); diff --git a/lib/routes/novel/ptwxz.js b/lib/routes/novel/ptwxz.js new file mode 100644 index 000000000..e0870db1b --- /dev/null +++ b/lib/routes/novel/ptwxz.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +const baseUrl = 'https://www.ptwxz.com/bookinfo/'; + +// 获取小说的最新章节列表 +module.exports = async (ctx) => { + // 小说id + const id1 = ctx.params.id1; + const id2 = ctx.params.id2; + const id = id1 + '/' + id2; + + const response = await got({ + method: 'get', + url: `${baseUrl}${id}.html`, + headers: { + Referer: `${baseUrl}${id}.html`, + }, + responseType: 'buffer', + }); + const responseHtml = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(responseHtml); + + const title = $('span>h1').text(); + + const list = $('.grid>tbody>tr>td>li>a'); + + ctx.state.data = { + title: `${title}`, + link: `${baseUrl}${id}.html`, + description: '', + item: + list && + list + .map((index, item) => { + item = $(item); + + return { + title: item[0].children[0].data, + description: '', + link: item.attr('href'), + }; + }) + .get(), + }; +};