feat: 增加小说-飘天文学 (#3765)

This commit is contained in:
LJason
2020-01-17 10:50:02 +08:00
committed by DIYgod
parent 03077673d0
commit 6138bbc9c1
3 changed files with 58 additions and 0 deletions

View File

@@ -106,6 +106,16 @@ pageClass: routes
</Route>
## 飘天文学
### 章节
<Route author="LJason77" example="/novel/ptwxz/10/10272" path="/novel/ptwxz/:id1/:id2" :paramsDesc="['小说网站链接倒数第二部分的数字, 可在对应小说页 URL 中找到, 例如 `10`', '小说网站链接最后的数字, 可在对应小说页 URL 中找到, 例如 `10272`']" >
举例网址https://www.ptwxz.com/bookinfo/10/10272.html
</Route>
## 起点
### 章节

View File

@@ -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'));

47
lib/routes/novel/ptwxz.js Normal file
View File

@@ -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(),
};
};