gpt4 book ai didi

javascript - 如何多次调用 casper.start()

转载 作者:行者123 更新时间:2023-11-29 18:02:23 24 4
gpt4 key购买 nike

我想在我的脚本中多次调用 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();

关于javascript - 如何多次调用 casper.start(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33987621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com