diff --git a/docs/reading.md b/docs/reading.md index 6b38aeb784..4c6076630b 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 647f76b2f8..086dde1d63 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 0000000000..e0870db1bd --- /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(), + }; +};