casperjs/phantomjs分割故障[英] CasperJS/PhantomJS Segmentation fault

问题描述

i有一个脚本,该脚本在链接数组中打开URL,对于每个URL,它在URL中提取链接并将新链接插入到数组链接(addLinks函数).该代码会导致分割故障,并在调用此时发生.开始打开有效的URL(代码的第三行). 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 casper.run 在您的脚本中.您可以将this.start重命名为this.thenOpen和this.run this.then.

本文地址:https://www.itbaoku.cn/post/1740027.html