使用casperjs下载文件

时间:2016-12-01 08:50:29

标签: javascript phantomjs casperjs slimerjs

在普通浏览器中,如果我点击链接,浏览器将打开一个对话框来保存/打开文件。

如何使用casperjs自动化这个东西。以下是html代码

<li>
    <a id="rmdExport" href="#">Export markdown file</a>
</li>
单击

后,将打开浏览器窗口 我尝试使用以下代码,但没有工作

casper.then(function(){
    functions.open_advanceddiv(casper);
    casper.setFilter("page.prompt", function (msg, currentValue) {
        if (msg === "You have choosen to open:") {
            return true;
        }
    });
    this.click("#rmdExport");
});
casper.on('resource.received', function(resource) {
    if (resource.stage !== "end") {
        console.log("resource.stage !== 'end'");
        return;
    }
    if (resource.url.indexOf(Notebook+'.Rmd') > -1) {
        console.log("Downloading md file");
        this.download(resource.url, file+'.md');
    }
});
casper.then(function (){
    Notebook = this.fetchText(".jqtree-selected > div:nth-child(1) > span:nth-child(1)");
    this.page.onFileDownload = function(status){console.log('onFileDownload(' + status + ')'); 
    //SYSTEM WILL DETECT THE DOWNLOAD, BUT YOU WILL HAVE TO NAME THE FILE BY YOURSLEF!!
    return Notebook+".md"; };
});

我浏览了这些链接How i can save/download link with blob: ?casperjs download csv filedownloading a file that comes as an attachment in a POST request response in PhantomJs

我知道所有这些的重复问题。但我很无奈,请帮助我这个

0 个答案:

没有答案