使用Casperjs我从远程服务器下载了一些apk但获得了一个空的apk(0字节)。
try {
this.echo("Attempting to download file ");
var fs = require('fs');
var appUrl = 'http://website.com/download/someapp.apk';
casper.download(appUrl, fs.workingDirectory+'/'+'newApk.apk');
} catch (e) {
this.echo(e);
}
我正在回应Headers。
Server: nginx/1.10.2
Date: Mon, 15 May 2017 06:49:10 GMT
Content-Length: 0
Connection: keep-alive
X-Robots-Tag: noindex
Location:http://website.com/download/someapp.apk
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache, max-age=0, no-cache, no-store, must-
revalidate, proxy-revalidate, no-transform
Pragma: no-cache
答案 0 :(得分:0)
如果网址正确且您的代码有效,则应该有效。为了帮助您,这是一个最小的工作示例脚本,用于在当前目录中下载图像:
var casper = require('casper').create();
casper.start('https://duckduckgo.com', function() {
var url = 'https://duckduckgo.com/assets/logo_homepage.normal.v107.svg';
this.download(url, 'duckduckgo-logo.svg');
});
casper.run(function() {
this.echo('Done.').exit();
});
如果仍然无效,则可能是安全的问题。在这种情况下,尝试使用casperjs --web-security=no download.js
运行脚本或者像这样配置Casper实例:
var casper = require('casper').create({
pageSettings: {
webSecurityEnabled: false
}
});
或强>
casper.page.settings.webSecurityEnabled = false;