У меня есть скрипт, который открывает URL-адреса в массиве ссылок, и для каждого URL-адреса он извлекает ссылки в этом URL-адресе и вставляет новые ссылки на ссылки массива (функция addLinks). Код приводит к ошибке сегментации, и это происходит, когда он вызывает this.start, чтобы открыть действительный URL-адрес (3-я строка кода). Это проблема с casperjs или моим кодом?CasperJS/PhantomJS Ошибка сегментации
Еще один интересный момент заключается в том, что он всегда печатает «ОК, он загружается» после «Название страницы:», в то время как в соответствии с кодом они должны быть напечатаны в обратном порядке. Не могли бы вы рассказать мне причину этого странного поведения?
// 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)