尝试通过casperjs启动方法打开随机页面,但有些页面正在正确加载,而有些页面没有加载,因此在这种情况下,它不会退出casperJS。它被卡在控制台中,然后需要使用CTR+C手动退出控制台。
casper.start("some url", function() {
if(this.status().currentHTTPStatus == 200) {
casper.echo("page is loading");
} else {
casper.echo("page is in error ");
this.exit();
}
});发布于 2016-07-04 06:40:58
然后用全局stepTimeout选项对其进行包装。
样本代码:
var casper = require('casper').create({
stepTimeout: 10000 //10s
})
casper.start()
casper.then(funtion(){
casper.open(url)
})
casper.run()发布于 2016-07-01 15:31:41
尝试bypass()忽略下一个_then_s。
casper.start("some url", function() {
if(this.status().currentHTTPStatus == 200) {
casper.echo("page is loading");
} else {
casper.echo("page is in error ");
this.bypass(2); // Will not execute the then functions.
}
}).then(function() {
// The 1st then function.
}).then(function() {
// The 2nd then function.
})
casper.run(function() {
this.echo('Something');
this.exit(); // <--- Here.
});https://stackoverflow.com/questions/38139859
复制相似问题