Trigger function on Page's requestfinished event
Created by: sebastienfi
Hi
First of all, thanks for relasing this, awesome work guys
I would like to access the Browser's Page's requestfinished
event.
I believe that event: 'requestfinished' is the Crawler's requestfinished
event.
My intention is to download the ressources of the page (images, fonts, ...). I'm planning to do something like this :
// On my previous setup, page originates from
// const browser = await puppeteer.launch()
// const page = await browser.newPage()
page.on('requestfinished', async request => {
// do something with request
const url = request.url()
const match = /.*\.(jpg|png|gif)$/.exec(url)
if (match && match.length === 2) {
const split = url.split('/')
let filename = split[split.length - 1]
const response = request.response()
const buffer = await response.buffer()
fs.writeFileSync(`${crawlPathImages}/${filename}`, buffer, 'base64')
}
})
How can I do this using your crawler ?