如何多次调用 casper.start()

How to call casper.start() multiple times

我想在脚本中多次调用 casper.start()

我试过:

var ids = [1,6,13];

ids.forEach(function(id) {
    casper.start('http://localhost/mypage?id='+id, function() { });
});

casper.then(function() {
....

但是,只有最后一个 id 被执行。

可以多次调用casper.start()吗?如果可以,怎么做?

start() 只应为一个 casper 对象调用一次。您只会看到一次调用,因为对 start() 的第二次调用会重置内部状态。您可以使用 thenOpen() 打开多个页面:

var ids = [1,6,13];

casper.start();

ids.forEach(function(id) {
    casper.thenOpen('http://localhost/mypage?id='+id, function() {
        this.capture("id.png");
    });
});

casper.run();