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!