1

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

我如何使用 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"; };
});

我浏览了这些链接如何使用 blob 保存/下载链接:?, casperjs 下载 csv 文件, 下载作为附件出现在 PhantomJs 中的 POST 请求响应中的文件

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

4

0 回答 0