CasperJS/PhantomJS Segmentation fault
CasperJS/PhantomJS Segmentation fault
我有一个脚本,它打开链接数组中的网址,对于每个网址,它提取该网址中的链接,并将新链接插入到数组链接(addLinks函数)。代码会导致分段错误,当它调用 this.start 打开有效的 url(代码的第 3 行)时会发生。是卡斯珀斯还是我的代码有问题?
另一个有趣的点是,它总是在"页面标题:"之后打印"好的,它已加载",而根据代码,它们应该以相反的顺序打印。你能告诉我这种奇怪行为的原因吗?
// Just opens the page and prints the title
function start(link) {
this.echo('lets try the link:-- '+ link + ' -------------');
this.start(link, function() {
this.echo('Page title: ' + this.getTitle());
});
this.echo('OK, it is loaded'n');
}
function check() {
if (links[currentLink] && currentLink < upTo) {
this.echo('--- Link ' + currentLink + ' ---');
start.call(this, links[currentLink]);
addLinks.call(this, links[currentLink]);
currentLink++;
this.run(check);
} else {
this.echo("All done.");
this.exit();
}
}
casper.start().then(function() {
this.echo("Starting");
});
casper.run(check);
这是我的代码的结果:
---链接 0 ---让我们尝试链接:-- http://yahoo.com -------------好的,它已加载页面标题: 雅虎http://yahoo.com 找到 111 个链接http://yahoo.com 找到 13 个脚本找到 0 帧 http://yahoo.com 帧源:新帧源:---链接 1 ---让我们尝试链接:-- http://everything.yahoo.com/-------------好的,它已加载PhantomJS崩溃了。请阅读崩溃报告指南...分段故障(核心转储)
在脚本中仅使用一次casper.start
和casper.run
。您可以将this.start
重命名为 this.thenOpen
,this.run
重命名为 this.then
。