我创建了一个脚本,该脚本登录到我的银行帐户,导航到交易页面,然后尝试下载所有交易数据的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。也许这暗示出什么问题了?
仅单击链接似乎并未导致应该发生的onClick javascript调用。所以,然后我测试了:
casper.then(function(){
//casper.click(x("//a[contains(text(), 'Download')]"));
casper.evaluate(function(){
urchinTracker('/download_transactions/continue');
submitForm('download');
return false;
});
});
casper.on('resource.received', function(resource) {
//console.log(resource.url);
if (resource.stage !== "end") {
return;
}
if (resource.url.indexOf('download.qfx') !== -1) {
this.download(resource.url, 'ExportData.csv');
}
});
因此,由于某种原因,有必要分别调用onClick函数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句