I am using Nightmare to create a automated downloader for today\'s newspaper. I managed to login and go the the specified page. However I could not find out how to download
I got my downloads super easy using the request module, as described here.
var Nightmare = require('nightmare');
var fs = require('fs');
var request = require('request');
new Nightmare()
.goto('https://login.nrc.nl/login?service=http://digitaleeditie.nrc.nl/welkom')
.insert('input[name="username"]', 'Username')
.insert('input[name="password"]','Password')
.click('button[type="submit"]')
.wait()
.goto('http://digitaleeditie.nrc.nl/digitaleeditie/NH/2014/10/20141124___/downloads.html')
.wait()
.then(function () {
download('http://digitaleeditie.nrc.nl/digitaleeditie/helekrant/epub/nrc_20141124.epub', 'myBook.epub', function () {
console.log('done');
});
})
.catch(function (err) {
console.log(err);
})
function download(uri, filename, callback) {
request.head(uri, function () {
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
}
Run npm i request
in order to use request
.