javascriptajaxphantomjscasperjs

problem CasperJS POST via AJAX not working


I'm working on a scraper of my bank statements with CasperJS, so far I've managed to login and get to the statements page. I accomplished to get the table with the first page of the statement, but I need to get it complete.

The bank's web have the option to export to a .txt file (sort of a CSV actually), but in order to download it I have to be able to download the file that comes as an attachment in the response header of a POST request when I submit a form by clicking a button.

So I figured that I could do the POST via AJAX, get the response and output it. I tried running the code on the firebug console and it works, but for some reason it just doesn't work in CasperJS.

Btw, I have tried using --web-security=no , still doesn't work

This is how I'm trying to do it:

            this.then(function() {
                eurl = "http://bankurl.com";
                response = this.evaluate(function() {
                params = $("#lForm").serialize();
                $.ajax({
                    type: "POST",
                    url: eurl,
                    data: params,
                    success: function (data) {
                        return data.responseText;
                    },
                    error: function (xhr,status,error){
                        return error;
                    }

                });
            });
            this.echo(response);
        });

Solution

  • Well, after struggling finding a way to solve this I finally did, I just put the ajax call inside a try catch and found that the error was that it wasn't reading the eurl variable (I declared it outside the evaluate). I put it inside and it worked. Thanks for your help