diff --git a/lib/routes/cartoonmad/comic.js b/lib/routes/cartoonmad/comic.js index 66b6bc010..8e3909621 100644 --- a/lib/routes/cartoonmad/comic.js +++ b/lib/routes/cartoonmad/comic.js @@ -3,16 +3,25 @@ const cheerio = require('cheerio'); const axios = require('../../utils/axios'); const iconv = require('iconv-lite'); -const getChapters = ($) => +const getChapters = (id, $) => $('#info') .eq(1) .find('a') .map((_, ele) => { const a = $(ele); + const link = resolve('https://www.cartoonmad.com/', a.attr('href')); + const title = a.text(); + const num = a.next('font').text(); + let contentBody = ''; + for (let page = 1; page <= parseInt(/\d+/.exec(num)); page++) { + contentBody += `
`; + } + return { - link: resolve('https://www.cartoonmad.com/', a.attr('href')), - title: a.text(), - num: a.next('font').text(), + link, + title, + num, + contentBody, }; }) .toArray() @@ -21,7 +30,13 @@ const getChapters = ($) => module.exports = async (ctx) => { const { id } = ctx.params; - const { data } = await axios.get(`https://www.cartoonmad.com/comic/${id}`, { responseType: 'arraybuffer' }); + const { data } = await axios.get(`https://www.cartoonmad.com/comic/${id}`, { + responseType: 'arraybuffer', + headers: { + Host: 'www.cartoonmad.com', + Referer: 'https://www.cartoonmad.com/', + }, + }); const content = iconv.decode(new Buffer.from(data), 'big5'); const $ = cheerio.load(content); @@ -33,19 +48,16 @@ module.exports = async (ctx) => { .find('td') .text() .trim(); - const coverImgSrc = $('.cover') - .parent() - .find('img') - .attr('src'); - const chapters = getChapters($); + // const coverImgSrc = $('.cover') + // .parent() + // .find('img') + // .attr('src'); + const chapters = getChapters(id, $); const genResult = (chapter) => ({ link: chapter.link, title: chapter.title, - description: ` -

${chapter.num}

- - `.trim(), + description: chapter.contentBody, }); ctx.state.data = { title: `動漫狂 - ${bookTitle}`,