javascript - CasperJS/PhantomJS 段错误

标签 javascript segmentation-fault phantomjs casperjs

我有一个脚本,它打开链接数组中的网址,对于每个网址,它提取该网址中的链接并将新链接插入数组链接(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.startcasper.run一次。您可以将 this.start 重命名为 this.thenOpen,将 this.run 重命名为 this.then

关于javascript - CasperJS/PhantomJS 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27643869/

相关文章:

python - 无法使用 ghostdriver 启动 phantomjs

javascript - jQuery:如何更改点击事件的数据绑定(bind)?

javascript - 使用 Node.js 与 bash 交互

有人可以向我解释为什么这段代码会给我一个段错误吗?

c++ - 在抛出 'std::length_error' what(): basic_string::_S_create 实例后终止调用

javascript - 如何在 CasperJS 中的多个页面上进行嵌套循环

javascript - 在 CasperJS 中使用eachThen和thenOpen在超时时继续下一个URL

javascript - 在不支持 vw 或 vh 属性的旧移动浏览器中会发生什么情况?

javascript - 用 Cloudmade map 替换 Google map ?

找不到这段代码的错误。 (SIGSEGV)