From 1cb4559e3d1692c3b4da052bcba34e94432d43c5 Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Sun, 15 Nov 2020 21:41:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=BA=E7=8C=AC=E7=8C=ABRSS=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20#6170=20(#6174)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/ciweimao/chapter.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/routes/ciweimao/chapter.js b/lib/routes/ciweimao/chapter.js index b9cf00094..9c93e522e 100644 --- a/lib/routes/ciweimao/chapter.js +++ b/lib/routes/ciweimao/chapter.js @@ -3,27 +3,32 @@ const cheerio = require('cheerio'); module.exports = async (ctx) => { const id = ctx.params.id; + const selector = cheerio.load((await got.get(`https://www.ciweimao.com/book/${id}`)).data); + const name = selector('.book-info h3.title').text(); + const description = selector('.book-intro').html(); const response = await got({ - method: 'get', - url: `http://www.ciweimao.com/chapter-list/${id}/book_detail`, + method: 'post', + url: `https://www.ciweimao.com/chapter/get_chapter_list_in_chapter_detail`, + form: { + book_id: id, + chapter_id: 0, + orderby: 0, + }, }); const $ = cheerio.load(response.data); - const name = $('.book-catalog>.hd>h3').text(); - - const chapter_item = []; - - $('.book-chapter>.book-chapter-box>ul>li>a').each(function () { - chapter_item.push({ - title: $(this).text(), - link: $(this).attr('href'), - }); - }); + const item = $('.book-chapter-box>ul>li>a') + .map((index, ele) => ({ + title: $(ele).text(), + link: $(ele).attr('href'), + })) + .get(); ctx.state.data = { title: `刺猬猫 ${name}`, link: `http://www.ciweimao.com/book/${id}`, - item: chapter_item, + description, + item, }; };