From 98afb195299ef371254c8381a67e9bcfbcdd9832 Mon Sep 17 00:00:00 2001 From: zytomorrow Date: Fri, 10 May 2019 01:12:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A8=E6=BC=AB=E7=8B=82=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0herder=20referer;rss=E6=AD=A3=E6=96=87=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=B8=BA=E5=85=A8=E9=83=A8=E5=86=85=E5=AE=B9=20(#2091?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 动漫狂添加herder referer;rss正文输出为全部内容 --- lib/routes/cartoonmad/comic.js | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/routes/cartoonmad/comic.js b/lib/routes/cartoonmad/comic.js index 66b6bc0106..8e3909621d 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}`,