【发布时间】:2015-09-21 13:58:31
【问题描述】:
我创建了一个脚本,用于登录我的银行帐户,导航到交易页面,然后尝试下载所有交易数据的 CSV。但是,单击“下载”按钮后,资源永远不会被下载。单击按钮时调用的资源是“download.qfx”,每次都会生成不同的文件名。任何帮助将不胜感激。
// When download page loads, click the appropriate settings and download transactions
casper.then(function(){
this.waitForSelector("#transactionPeriod", function() {
this.evaluate(function() {
document.querySelector('#transactionPeriod').selectedIndex = 0; //it is obvious
return true;
});
this.clickLabel("Spreadsheet (Comma Separated Values)", "label");
});
});
// Click the download button
casper.then(function(){
casper.click(x("//a[contains(text(), 'Download')]"));
});
// Save the download file
casper.then(function(){
casper.download("https://secure.capitalone360.com/myaccount/download.qfx", "export.csv");
});
更新: 我也试过了,但是“下载”点击事件后调试器没有输出。
casper.then(function(){
casper.click(x("//a[contains(text(), 'Download')]"));
});
casper.on('resource.received', function(resource) {
if (resource.stage !== "end") {
console.log("resource.stage !== 'end'");
return;
}
if (resource.url.indexOf('download.qfx') > -1) {
console.log("Downloading csv file");
this.download(resource.url, 'ExportData.csv');
}
});
此外,如果我输入 console.log(resource.url),我永远不会看到 download.qfx。也许这暗示出了什么问题?
【问题讨论】:
-
没有。它在 GET 请求中。
-
您尝试过解决方案吗?
-
我已经尝试过更新中提到的那个。按钮单击事件后没有输出(在调试中)。 PhantomJS 2.0 有很多我一直试图避免的问题,所以第一个答案不是一个很好的解决方案。
标签: javascript download click casperjs