* fix: zhaishuyuan content incomplete (#6877) * fix: remove unused var * [CodeFactor] Apply fixes to commit c8e441a [ci skip] [skip ci] Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
parent
771d9d6356
commit
fd776393b5
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue