CasperJS / PhantomJS分段故障

时间:2014-12-25 02:58:01

标签: javascript segmentation-fault phantomjs casperjs

我有一个脚本打开links数组中的url,每个url都会提取该url中的链接并将新链接插入到数组链接(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)

1 个答案:

答案 0 :(得分:1)

在脚本中仅使用casper.startcasper.run 一次。您可以将this.start重命名为this.thenOpen,将this.run重命名为this.then