Download img/png mime type , casperJS

こ雲淡風輕ζ 提交于 2019-12-24 14:27:32

问题


I'm having a casperJS script to trigger an image download on a button click. I have clicked the button, and the resouce.recived has a file of type image/png. How do I download that and save ? When I tried download(resource, "something.png); I get to download HTML(source code of the page) and not the desired image. Relevant segment of my code :

var dFile = casper.on('page.resource.received', function(resource) {
    if (resource.stage !== "end") {
        return;
    }
    if(resource.contentType.indexOf('image') >= 0)
    {
        console.log(resource.status);
        console.log(resource.contentType);
    }
    console.log("Downloading");
    casper.download(resource, "test011.png");

    dFile = resource;
    return dFile;
});

I've had a look at this, downloading a file that comes as an attachment in a POST request response in PhantomJs and tried implementing the solution, but doesn't seem to work. I'm new to Casper and JavaScript as well. Please let me know how to go about this. Thanks !

来源:https://stackoverflow.com/questions/30405704/download-img-png-mime-type-casperjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!