2014-12-25 1 views
0

링크 배열의 URL을 여는 스크립트가 있습니다. 각 URL에 대해 해당 URL의 링크를 추출하고 배열 링크 (addLinks 함수)에 새 링크를 삽입합니다. 이 코드는 세그먼테이션 오류를 발생시키고 this.start를 호출하여 유효한 URL (코드의 세 번째 줄)을 열 때 발생합니다. casperjs 또는 제 코드에 문제가 있습니까?CasperJS/PhantomJS 분할 오류

또 다른 흥미로운 점은 '페이지 제목 :'다음에 항상 'OK,로드 됨'이 인쇄되는 반면 코드는 역순으로 인쇄되어야한다는 점입니다. 이 이상한 행동의 이유를 말씀해 주시겠습니까?

 
--- 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

사용 casper.startcasper.run 스크립트에서 한 번만 : 여기

// 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); 

는 내 코드의 결과입니다. this.startthis.thenOpenthis.runthis.then으로 바꿀 수 있습니다.