CasperJS/PhantomJS分段错误 [英] CasperJS/PhantomJS Segmentation fault
问题描述
我有一个脚本,用于打开links数组中的URL,并针对每个URL提取该URL中的链接,并将新链接插入到数组links(addLinks函数)中.该代码会导致分段错误,并且在调用this.start时会发生这种错误,请打开一个有效的url(代码的第三行). casperjs或我的代码有问题吗?
I have a script which opens the urls in the links array and for each url it extracts the links in that url and inserts the new links to the array links(addLinks function). The code results in segmentation fault and it happens when it calls this.start to open a valid url (3rd line of the code). Is it a problem with casperjs or my code?
另一个有趣的一点是,它总是在页面标题:"之后打印确定,它已加载",而根据代码,它们应该以相反的顺序打印.您能告诉我这种奇怪行为的原因吗?
Another interesting point is that it always prints 'OK, it is loaded' after the 'Page title: ' while according to the code they should be printed in reverse order. Would you please tell me the reason for this strange behaviour?
// 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
.
Use casper.start
and casper.run
only once in your script. You can rename this.start
to this.thenOpen
and this.run
to this.then
.
这篇关于CasperJS/PhantomJS分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!