Я нашел этот вопрос и последовал за ним downloading a file that comes as an attachment in a POST request response in PhantomJs. Но файл, который он сохраняет, является html-файлом и говорит 404 - File or directory not found.
Есть ли что-то еще, что мне не хватает, чтобы загрузить этот файл csv?Casperjs Загрузить Вложение Сообщество
Вот заголовки ответа
Cache-Control:private
Content-Disposition:attachment;filename=LenderCompetitionReport.csv
Content-Length:249487
Content-Type:application/csv
Date:Tue, 08 Dec 2015 14:32:47 GMT
Pragma:
Server:Microsoft-IIS/7.0
Set-Cookie:NSC_JOy4ob05etjhas0d2kv5wzcdlqr2zbu=ffffffff09149e4f45525d5f4f58455e445a4a423660;expires=Tue, 08-Dec-2015 14:34:47 GMT;path=/;secure;httponly
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
И вот мой код
casper.waitForSelector(x("//*[@id='ContentBody_ContentBody_btnExport']"),function() {
casper.then(function() {
var res = this.page.evaluate(function() {
var res={};
f=document.forms["frmBase"];
f.onsubmit= function() {
//iterate the form fields
var post={};
for(i=0; i<f.elements.length; i++) {
post[f.elements[i].name]=f.elements[i].value;
}
res.action = f.action;
res.post = post;
return false; //Stop form submission
}
//Trigger the click on the link.
var l = $("#ContentBody_BodyLevelElment_lbtnCsv");
l.click();
return res; //Return the form data to casper
});
//Start the download
casper.download(res.action, "LenderCompetitionReport.csv", "POST", res.post);
});
});
Просто, чтобы быть ясным: что находится в res.action? casper.download() ожидает, что URL-адрес будет первым аргументом. –