2017-05-24 4 views
0

一般的にCasperJSとJavaScriptを使用するのは初めてです。現時点では、git repoからファイルをダウンロードする方法を学びたいと思っています。参照ページを読んでいるうちに、私はCasperJSが持っているダウンロード方法を見つけました。その結果、私は次のことを試してみました:指定されたファイルをダウンロードする代わりに、CasperJSのコピー用のフォルダパスをダウンロードします。

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); 
}); 

これに伴う問題は、絶対に同じである代わりに、指定されたパスに自分のコンピュータに単にファイルをダウンロードする、それの代わりにコピーする部分ディレクトリ・パスということです作成されたパス(コンテンツも含まれません)。私は何かが間違っていた(私はそう仮定することができる)か、何か、誰かが私を助けてくれるかどうかは分からない。

P.S. :これらのファイルを別の方法でダウンロードするほうが簡単でしょうか?もし必要ならば、それが行われます。時間と助けを前もって感謝します。

+0

また、waitForUrlメソッドを使用した後、終了タイムアウトが5000msだったため、終了しました。私はこれが問題に関連していると仮定することができます。まだ周囲を見回している。 –

+0

^待ち時間を20秒に増やそうとしましたが、まだ動作しません。だから私はそれが問題ではないと仮定します。 –

答えて

0

長い休憩を取って戻ってきたとき、私はそれが簡単な間違いであることに気付きました。まず、2つの絶対パスをつなぎ合わせたので、ディレクトリを2回コピーしていたのです。

ファイルのダウンロードに関して、私はCasperJS内でメソッドのパスを指定する必要はなく、現在の作業ディレクトリに配置することを学びました。隠しファイルを追加するときは注意してください。わかるように、隠されているからです。例えば、私は.gitignoreをダウンロードしました。隠されていたので、私がこの作業を行っていたディレクトリの "ls -a"を実行するまで、私はそれを見ることができませんでした。

私も私がファイルや.txtのために.javaのような特定の拡張子を指定したとしても、このメソッドはHTMLをダウンロードするだけなので、実際のファイルをgitリポジトリ内で関連させたい場合は、私はまだ現在探している。

var casper = require('casper').create(); 
var url = null; 
var utils = require('utils'); 
var http = require('http'); 
var fs = require('fs'); 
casper.options.waitTimeout = 20000; 

// 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.thenOpen('https://github.com/gabegomez014/SSS', function() { 
    url = 'https://github.com/gabegomez014/SSS/tree/master/src/SolarSystem/' 
    this.download(url, 'Algorithms.java'); 
}); 

// 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); 
}); 

// To let me know that all of the functions have finished and all done 
casper.then(function(){ 
    console.log('complete'); 
}); 

casper.run(); 
関連する問題