I am using puppeteer for web scraping, i need to setup a request interception to read a file that is being downloaded from the browser without actually downloading it because it takes a lot of resources to download read and then delete it.
I have already identified the request, but found no way to read from it
await pages[0].setRequestInterception(true);
pages[0].on('request', request => {
if (request.resourceType() === 'font' || request.resourceType() === 'stylesheet' || request.resourceType() === 'image') {
request.abort();
} else {
request.continue();
}
});
I'd rather use the response event because the request interception doesn't have the response yet.
pages[0].on('response', async response => {
if (response.request() /*Your condition check*/) {
var buffer = await response.buffer(); /*You can get the buffer*/
var content = await response.text(); /*You can get the content as text*/
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With