CasperJS:退出不工作
CasperJS: exit not working
尝试通过 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();
}
});
尝试bypass()
忽略下一个然后。
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.
});
使用全局 stepTimeout 选项将其包装在 then 步骤中。
示例代码:
var casper = require('casper').create({
stepTimeout: 10000 //10s
})
casper.start()
casper.then(funtion(){
casper.open(url)
})
casper.run()
尝试通过 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();
}
});
尝试bypass()
忽略下一个然后。
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.
});
使用全局 stepTimeout 选项将其包装在 then 步骤中。
示例代码:
var casper = require('casper').create({
stepTimeout: 10000 //10s
})
casper.start()
casper.then(funtion(){
casper.open(url)
})
casper.run()