I am new to working with CasperJS and JavaScript in general. At the moment, I am trying to learn how to download a file from a git repo. While reading the reference page, I stumbled upon the download method that CasperJS has. As a result, I have tried the following:
var casper = require('casper').create();
var url = null;
var utils = require('utils');
var http = require('http');
var fs = require('fs');
// A test to make sure that we can go into a github without any authentication
casper.start('https://github.com/gabegomez014/Test2', function(){
this.echo(this.getTitle(), 'INFO');
});
// A test for how the download function works
casper.then(function(){
url = 'https://github.com/gabegomez014/Test2/blob/master/.gitignore';
var cwd = fs.absolute('.');
var parent = fs.absolute("../");
var path = cwd + parent;
this.download(url, path);
});
// A test in order to get the current HTTP status of links that have been put into the function
// Attempt 3 works and cleaner
casper.thenOpen('https://github.com/gabegomez014/Test2/blob/master/.gitignore', function(){
var res = this.status(false);
this.echo(res.currentHTTPStatus);
});
The problem with this is that instead of downloading just the file to my computer at the specified path, it instead copies a partial directory path that is identical to the absolute path that was created (without their content as well). I can not tell if something I did was wrong (I can only assume so), or what, but can someone please help me?
P.S. : Would it just be easier to download these files in another way? Cause if it is necessary, it will be done. Thanks in advance for the time and help.