Download file with casperjs

59 views
Skip to first unread message

Yann Penet

unread,
Jul 20, 2016, 10:08:14 AM7/20/16
to CasperJS
Hello,

I want to download file from a site.

I do :

casper.then(function() { 
     this.click('a[data-xiti-link="telecharger"]');
     this.wait(6000);
     end=true;
});

I receive :

{
    "contentType": "application/json; charset=UTF-8",
    "headers": [
        {
            "name": "Server",
            "value": "nginx"
        },
        {
            "name": "Date",
            "value": "Wed, 20 Jul 2016 07:58:42 GMT"
        },
        {
            "name": "Content-Type",
            "value": "application/json; charset=UTF-8"
        },
        {
            "name": "Content-Length",
            "value": "391"
        },
        {
            "name": "Connection",
            "value": "keep-alive"
        },
        {
            "name": "Keep-Alive",
            "value": "timeout=30"
        },
        {
            "name": "X-Request-Id",
            "value": "b6436d20-d793-4bf6-84a2-5cca0fee125e"
        }
    ],
    "id": 58,
    "redirectURL": null,
    "stage": "end",
    "status": 200,
    "statusText": "OK",
    "time": "2016-07-20T07:57:59.399Z",
    "url": "https://api.bouyguestelecom.fr/comptes-facturation/XXXXXXX/factures/135177667?pfi=XXXXXXX&cache=false"
}

The code  :

casper.on('resource.received', function(resource) {
    if (resource["stage"]=="end") {       
        this.echo(JSON.stringify(resource, null, 4));   
        this.download(resource['url'],'file.pdf');       
    }
});


It doesn't work. How can I do to download the file with this header ?

Please  help me,

Thanks,

Yann

Yann Penet

unread,
Jul 26, 2016, 8:57:16 AM7/26/16
to CasperJS
Hello,

No response ...???

May be, beacause casperjs can't download file ???
If it's impossible, can you tell me ..

Thanks

Yann

Ken

unread,
May 25, 2017, 7:48:01 PM5/25/17
to CasperJS

casper.on('resource.received', function(resource) {

if (resource.stage !== 'end') return;

if (resource.url.indexOf('archive/master.zip') > -1)

this.download(resource.url, 'receive.zip');});

Reply all
Reply to author
Forward
0 new messages