this.page.on('response', async (response) => { const matches = /.*\.(jpg|png|svg|gif)$/.exec(response.url()); console.log(matches); if (matches && (matches.length === 2)) { const extension = matches[1]; const buffer = await response.buffer(); fs.writeFileSync(`downloads/${this.request.userData}.${extension}`, buffer, 'base64'); counter += 1; } });
preNavigationHooks: [ async (crawlingContext, gotoOptions) => { const { page, request } = crawlingContext; console.log('handlePageFunction'); page.on('response', async (response) => { const matches = /.*\.(jpg|png|svg|gif)$/.exec(response.url()); if (matches && (matches.length === 2)) { const extension = matches[1]; const buffer = await response.buffer(); fs.writeFileSync( `downloads/${request.userData.row.id}.${extension}`, buffer, 'base64' ); } }) } ]