Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NightmareJS: How to block loading resources?

I am making a small scraper with nightmareJS but loading all the external resources takes ages and consumes tons of bandwidth.

How can I only load the basic page html (without images, css etc)?

I couldn't find any relevant information online, maybe I'm looking in the wrong place.

like image 542
Gloomy Avatar asked Dec 06 '25 19:12

Gloomy


2 Answers

like this :)

const nightmare = Nightmare({
    show: true,
    webPreferences: {
        images: false
    }
});
like image 181
Hassan Gilak Avatar answered Dec 08 '25 15:12

Hassan Gilak


You can use webRequest.onBeforeRequest in tandem with Nightmare's .action() to filter content.

You might want to check out nightmare-load-filter (disclaimer: I'm the author), I believe that does what you're looking to do.

like image 32
Ross Avatar answered Dec 08 '25 13:12

Ross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!