3

I'm trying to download a file using PhantomJs headless browser. The button that I have to press to start the download is in a Javascript form. I don't know how to handle the download dialog box and I find no documentation about it.

I need to be logged to perform the download.

Does anyone information about this kind of action ?

Ralk
  • 443
  • 1
  • 6
  • 17
  • Accepting correct answers is considered polite on StackOverflow. Just click on grayed check box near voting buttons if the answer solves your problem. It will additionally motivate others to help you. – Vasily Ryabov Jan 11 '17 at 13:52

1 Answers1

1

Try to put this code in a button click event, or can use this raw code to get it:

var page = require('webpage').create();

page.settings.userName = 'your username here';

page.settings.password = 'your password here';

 var url = "your url comes here";
 var fs = require('fs');
 var path = 'index.html'; //here you can use a format of the file you want .json .txt etc.

 page.open(url, function (status) {
     if(status !== 'success') {
         console.log('Connection failed, page was not loaded!');
     } else {
         var content = page.content;
         fs.write(path,content,'w')
         phantom.exit();
     }
});

Also, check out this link How to download a csv file using PhantomJS.

Let me know if you need further help!

Sven Hakvoort
  • 3,543
  • 2
  • 17
  • 34