From fd776393b533befa40706840959a5c6abe51d698 Mon Sep 17 00:00:00 2001 From: Ving Date: Sun, 14 Feb 2021 02:19:26 +0800 Subject: [PATCH] fix: zhaishuyuan content incomplete (#6877) (#6878) * fix: zhaishuyuan content incomplete (#6877) * fix: remove unused var * [CodeFactor] Apply fixes to commit c8e441a [ci skip] [skip ci] Co-authored-by: codefactor-io --- lib/routes/novel/zhaishuyuan.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/routes/novel/zhaishuyuan.js b/lib/routes/novel/zhaishuyuan.js index aaefaedf9..482fcd0af 100644 --- a/lib/routes/novel/zhaishuyuan.js +++ b/lib/routes/novel/zhaishuyuan.js @@ -6,7 +6,7 @@ module.exports = async (ctx) => { const id = ctx.params.id; const url = 'https://www.zhaishuyuan.com'; const link = `${url}/book/${id}`; - let extendedGot = got.extend({ headers: { Referer: url }, responseType: 'buffer' }); + const extendedGot = got.extend({ headers: { Referer: url }, responseType: 'buffer' }); const response = await extendedGot.get(link); const html = iconv.decode(response.data, 'gb2312'); const $ = cheerio.load(html); @@ -17,13 +17,16 @@ module.exports = async (ctx) => { .find('a') .map((_, { attribs: { title, href } }) => ({ title, link: `${url}${href}` })) .get(); - extendedGot = got.extend({ headers: { Referer: link }, responseType: 'buffer' }); const item = await Promise.all( list.map( async ({ title, link }) => await ctx.cache.tryGet(link, async () => { - const response = await extendedGot.get(link); - const html = iconv.decode(response.data, 'gb2312'); + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + await page.goto(link); + const encoded = await page.$('#content > div > a'); + await encoded.evaluate((encoded) => encoded.click()); + const html = await page.evaluate(() => document.documentElement.innerHTML); const $ = cheerio.load(html); const content = $('#content'); content.find('div').remove();