2014-11-09 1 views
0

게시판이있는 ASP 페이지에서 1 페이지와 2 페이지의 스크린 샷을 가져 오려고합니다. 첫 번째 페이지에 액세스하고 스크린 샷을 저장하려면 casperjs를 사용하고 다음을 클릭하고 두 번째 페이지에서 스크린 샷을 찍으려고합니다.포스트 백으로 다음 페이지를 보려면 클릭하십시오.

내 코드는 다른 사이트에서도 잘 작동하지만,이 코드는 나에게 힘든 시간을줍니다.

var casper = require('casper').create({logLevel: "debug", verbose: true }); 
casper.start('http://www.slot.pt/JobVacancies', function() { 
    this.capture('Step1.png'); 
    this.wait(5000, function() { 
     this.click('#ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1)'); 
    }); 
}); 

casper.run(function() { 
    this.capture('Step2.png'); 
    this.echo('finished'); 
    this.exit(); 
}); 

디버그 정보 :

[info] [phantom] Starting... 
[info] [phantom] Running suite: 2 steps 
[debug] [phantom] opening url: http://www.slot.pt/JobVacancies, HTTP GET 
[debug] [phantom] Navigation requested: url=http://www.slot.pt/JobVacancies, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "http://www.slot.pt/JobVacancies" 
[debug] [phantom] Navigation requested: url=http://platform.twitter.com/widgets/tweet_button.d58098f8a7f0ff5a206e7f15442a6b30.pt.html#_=1415538373180&count=none&id=twitter-widget-0&lang=pt&original_referer=http://www.slot.pt/JobVacancies&size=m&text=S L O T - Ofertas de Emprego&url=http://www.slot.pt/JobVacancies, type=Other, willNavigate=true, isMainFrame=false 
[debug] [phantom] Successfully injected Casper client-side utilities 
[info] [phantom] Step anonymous 2/2 http://www.slot.pt/JobVacancies (HTTP 200) 
[debug] [phantom] Capturing page to /home/netlisbon/test/Step1.png 
[info] [phantom] Capture saved to /home/netlisbon/test/Step1.png 
[info] [phantom] Step anonymous 2/2: done in 1559ms. 
[info] [phantom] Step _step 3/3 http://www.slot.pt/JobVacancies (HTTP 200) 
[info] [phantom] Step _step 3/3: done in 1560ms. 
[info] [phantom] wait() finished waiting for 5000ms. 
[debug] [phantom] Mouse event 'mousedown' on selector: #ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1) 
[debug] [phantom] Mouse event 'mouseup' on selector: #ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1) 
[debug] [phantom] Mouse event 'click' on selector: #ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1) 
[info] [phantom] Done 3 steps in 6571ms 
finished 
[debug] [phantom] Capturing page to /home/netlisbon/test/Step2.png 
[info] [phantom] Capture saved to /home/netlisbon/test/Step2.png 

그러나, 두 스크린 샷이 동일한 페이지를 표시 ... 을 내가로 이동 다른 화살표를 클릭하려고 다음과 같이

내 코드입니다 마지막 페이지,하지만 같은 결과가 나옵니다.

내가 여기서 무엇을 잘못하고 있는지 알 수 있습니까?

답변

0

포스트 백 기능은 JavaScript이며 탐색 단계를 트리거하지 않습니다. 그러나 CasperJS의 단계는 현재 탐색 단계가 완료되기를 기다리기 때문에 다음 "페이지"가로드되기 전에 스크립트가 완료됩니다.

당신이이 중 하나를 클릭

this.wait(5000, function() { this.click('selector'); }); 
this.wait(5000); 

또는 더 나은 후 시간의 정적 양을 기다립니다, 당신은 표시 당신이하고 특정 페이지 기다려야하는 페이지를 추적 :

var page = 1; 
this.wait(5000, function() { 
    this.click('selector'); 
    page++; 
}); 
this.waitFor(function check(){ 
    return this.fetchText(".dxp-summary").indexOf("Page " + page + " of ") === 0; 
}, function then() { 
    // screenshot or whatever 
}); 
+0

해결되었습니다. 감사합니다. – peixotorms