3

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.

Gloomy
  • 1,091
  • 1
  • 9
  • 18

2 Answers2

9

like this :)

const nightmare = Nightmare({
    show: true,
    webPreferences: {
        images: false
    }
});
Hassan Gilak
  • 691
  • 9
  • 14
  • Worked for me! Thank you so much! :) – rinogo Apr 13 '17 at 22:08
  • Can you tell me where you found that information? The official documentation doesn't mention it but it works. Really awesome! – Matthis Kohli Jul 01 '17 at 21:21
  • 1
    @MatthisKohli nightmare used electron as a browser. so I found this on electron doc or somewhere related to it. – Hassan Gilak Jul 04 '17 at 01:39
  • `webPreferences` object is detailed here: https://github.com/electron/electron/blob/master/docs/api/browser-window.md#new-browserwindowoptions There's too many options for me to copy here in a comment. – Mr5o1 Oct 16 '17 at 09:16
1

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.

Ross
  • 2,448
  • 1
  • 21
  • 24