我正在使用CasperJS下载15 MB的文件.在浏览器中,下载大约需要3分钟才能完成.使用Casper,.download
相同url 的函数在30秒后返回,并且写入磁盘的文件为0字节.我已经尝试设置更长的超时时间:
var casper = require("casper").create({
pageSettings: {
webSecurityEnabled: false
},
waitTimeout: 500000,
stepTimeout: 500000
});
但它们没有效果.这是我的下载功能:
casper.on('resource.received', function (resource) {
var url, file;
if ((resource.url.indexOf("myDownloadUniqueString=") !== -1) ) {
this.echo(resource.url); // the echo'ed url can be downloaded in a web browser
url = resource.url;
file = "downloaded_file.wav"; // this will be 0 bytes
try {
var fs = require("fs"); // phantom js file system (not node)
casper.download(resource.url, file);
} catch (e) {
this.echo(e); // no error is thrown
}
}
});
有任何想法吗?也许PhantomJS fs
方法存在问题,但文档不完整......