我有一个脚本,它打开链接数组中的网址,对于每个网址,它提取该网址中的链接并将新链接插入数组链接(addLinks 函数)。该代码会导致段错误,并且当它调用 this.start 打开有效的 url(代码的第 3 行)时,就会发生这种情况。是casperjs的问题还是我的代码的问题?
另一个有趣的点是,它总是在“页面标题:”之后打印“确定,已加载”,而根据代码,它们应该以相反的顺序打印。您能告诉我这种奇怪行为的原因吗?
// 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);
这是我的代码的结果:
--- Link 0 --- lets try the link:-- http://yahoo.com ------------- OK, it is loaded Page title: Yahoo 111 links found http://yahoo.com 13 scripts found http://yahoo.com 0 frames found http://yahoo.com frame src: new frame src: --- Link 1 --- lets try the link:-- http://everything.yahoo.com/ ------------- OK, it is loaded PhantomJS has crashed. Please read the crash reporting guide... Segmentation fault (core dumped)
最佳答案
在脚本中仅使用casper.start
和casper.run
一次。您可以将 this.start
重命名为 this.thenOpen
,将 this.run
重命名为 this.then
。
关于javascript - CasperJS/PhantomJS 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27643869/