Is it possible to download a file to a folder and give it a specific name with panthomjs/casperjs ?
For instance how can I download the .csv at the bottom of this page : http://www.nasdaq.com/symbol/aapl/historical and name it aapl.txt ?
The download link is :
<a href="javascript:getQuotes(true);" id="lnkDownLoad">
Download this file in Excel Format
</a>
Its goal is to call a javascript function whose goal is to obfuscate the direct download link (I think) but when you click on it it summons a classic download prompt. I would like phantomjs to handle that download normally (to change the name of the file and chose where to save it on the drive disk)
Edit : This code is supposed to click on the download link and listen for incoming ressources :
var casper = require('casper').create();
var x = require('casper').selectXPath;
casper.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36")
casper.start('http://www.nasdaq.com/symbol/aapl/historical', function () {
//this.echo(this.getTitle());
console.log('TITLE : ' + this.getTitle());
});
casper.wait(5000, function() {
casper.on('resource.received', function (resource) {
casper.echo("LISTENING");
casper.echo(resource.url);
});
});
casper.thenClick(x('//*[@id="lnkDownLoad"]'), function() {
console.log('CLICKED');
});
casper.run();
But for some reason I dont receive any file unlike on a normal browser. The console log is : b'TITLE : (AAPL) Historical Prices & Data - NASDAQ.com\r\nCLICKED\r\nLISTENING\r\nhttp://www.nasdaq.com/symbol/aapl/historical\r\n'
Any idea ?