Forked from rosshinkley/nightmare-multiple-downloads.js
Created
January 29, 2016 09:43
-
-
Save thuongdinh-agilityio/abaddd2f183ad7d6c508 to your computer and use it in GitHub Desktop.
Download multiple files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Nightmare = require('nightmare'), | |
vo = require('vo'); | |
function *start() { | |
var nightmare = new Nightmare({ | |
show: true, | |
'download-preferences': { | |
destination: require('path').resolve(__dirname, 'downloads') | |
} | |
}); | |
var counter = 0; | |
nightmare.on('download-start', function(download){ | |
console.log('download start: ' + JSON.stringify(download,null,3)); | |
counter++; | |
}); | |
nightmare.on('download-done', function(download){ | |
console.log('download end: ' + JSON.stringify(download, null, 3)); | |
counter--; | |
}); | |
var dl = yield nightmare.goto('http://www.sample-videos.com') | |
.click('a[data="153"]') | |
.click('a[data="48"]') | |
.click('a[data="55"]') | |
.wait(3000); | |
while(counter > 0){ | |
yield nightmare.wait(1000); | |
} | |
console.log('all files downloaded'); | |
yield nightmare.end(); | |
} | |
vo(start)(function() { | |
console.log('done'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Base on comment of author at segment-boneyard/nightmare#332 (comment)
Install package with command: npm install https://github.com/rosshinkley/nightmare.git#auto-download
Work fine with node version 4.2