Download a file using Nightmare

前端 未结 4 1338
时光说笑
时光说笑 2020-12-15 12:25

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

4条回答
  •  一整个雨季
    2020-12-15 12:52

    There is a Nightmare download plugin. You can download the file just with this code below:

    var Nightmare = require('nightmare');
    require('nightmare-download-manager')(Nightmare);
    var nightmare = Nightmare();
    nightmare.on('download', function(state, downloadItem){
      if(state == 'started'){
        nightmare.emit('download', '/some/path/file.zip', downloadItem);
      }
    });
    
    nightmare
      .downloadManager()
      .goto('https://github.com/segmentio/nightmare')
      .click('a[href="/segmentio/nightmare/archive/master.zip"]')
      .waitDownloadsComplete()
      .then(() => {
        console.log('done');
      });

提交回复
热议问题