我正在尝试通过单击与CasperJS的aspx页面链接来下载可用的ZIP文件。但是我的程序失败并返回“加载资源失败,状态=失败(HTTP 200)”。
我的代码:
var casper = require('casper').create({
pageSettings: {
userName: 'myusername',
password: 'mypwd',
localToRemoteUrlAccessEnabled: 'true',
XSSAuditingEnabled: 'true',
webSecurityEnabled: false
}
});
casper.start('https://mysite/login.aspx');
casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
// some code for identification...
casper.thenOpen('https://mysite/mypage.aspx');
casper.waitForSelector(
'a[id="myidlink"]',
function() {
this.click('#myidlink');
},
function() {
this.log('TIMEOUT!','error');
this.exit(62);
},
10000
);
casper.waitForSelector('#myidlink');
casper.on('resource.received', function (resource) {
if (resource.contentType == "application/zip" && resource.stage == 'end'){
this.log('resource.id : ' + resource.id, 'info');
this.log('resource.url : ' + resource.url, 'info');
}
});
casper.run();
我使用命令:
在ubuntu终端中执行此代码casperjs --ignore-ssl-errors=true --web-security=false --ssl-protocol=any --verbose --log-level=debug mycasperjs.js
控制台日志返回“加载资源失败”:
[info] [phantom] Starting... ... [debug] [phantom] Mouse event 'mousedown' on selector: #myidlink [debug] [phantom] Mouse event 'mouseup' on selector: #myidlink [debug] [phantom] Mouse event 'click' on selector: #myidlink [info] [phantom] Step anonymous 9/10: done in 8142ms. [debug] [phantom] Navigation requested: url=https://mysite/mypage.aspx [warning] [phantom] Loading resource failed with status=fail (HTTP 200): https://mysite/mypage.aspx [info] [phantom] Step _step 10/10 mysite/mypage.aspx (HTTP 200) [info] [phantom] Step _step 10/10: done in 9890ms. [info] [phantom] resource.id : 49 [info] [phantom] resource.url : mysite/mypage.aspx [info] [phantom] waitFor() finished in 40ms. [info] [phantom] Done 10 steps in 9948ms
使用的版本:
phantomjs --version
1.9.2
casperjs --version
1.1.0-beta3
欢迎任何帮助!
非常感谢。