CasperJS - 如何并行打开链接数组中的所有链接

CasperJS - How to open up in parallel all links from an array of links

我需要并行打开数组的所有链接
怎么做到的?
在我的代码中,所有链接都会一个一个打开,而不是并行打开。
这是我的代码:

casper.then(function(){
     links = this.evaluate(function(){
        var links = document.getElementsByTagName('a');
        links = Array.prototype.map.call(links,function(link){
        return link.getAttribute('href');
        });
        return links;
    });
});
casper.then(function(){
    this.each(links,function(self,link){
     self.thenOpen(link,function(a){
     this.echo(this.getCurrentUrl());
     });
    });
});
casper.run(function(){this.exit()});

casper 对象表示单个浏览器 window。

一种方法是创建多个 casper 个对象,每个 URL 个对象并行创建一个。请注意 this is not officially supported,因此可能很脆弱。

另一种方法是使用 bash 脚本来启动 casperjs 的多个实例,并为每个实例提供一组要获取的 URL。这很好而且很干净(如果使用持久性 cookie,您可能希望确保它们每个都有自己的 cookie 文件:--cookies-file=/path/to/cookies.txt),但您可能更难编写脚本,具体取决于您获取初始列表的方式共 URL 秒。