나는 다음과 같은 경우 작업 casperjs 얻으려고 :특정 조건이 충족 될 때까지 casperjs를 반복 할 수 있습니까?
웹 페이지가로드, 그 페이지 내에서, 그와 함께로드 데이터 항목 을 Ajax를 버튼 '자세히'이것은 다시로드 일부에서 더 많은 데이터 상품.
로드 할 데이터 항목이 많으면 '더 읽기'버튼이 있는지 반복적으로 확인하려면 스크립트가 필요합니다. 그렇다면 클릭하고 나머지 스크립트를 계속 실행하여 전체를 출력하십시오 페이지로 jpeg.
아래 코드를 작성하여 시도했지만 희망했던대로 반복하지 않습니다. 더 많은 데이터가로드되고 버튼을 다시 클릭해도 여전히 버튼을 한 번 클릭 한 다음 이미지를 출력합니다.
var casper = require('casper').create({
verbose : true,
logLevel : 'debug',
pageSettings : {
"userAgent" : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Chrome/23.0.1262.0 Safari/537.10',
"loadImages" : false,
"webSecurityEnabled" : false,
"ignoreSslErrors" : true
},
});
var urls = {
login : 'http://www.website.com/login',
details : 'http://www.website.com/details',
};
casper.start(urls.login, function() {
//login stuff
});
//the function I'm trying to recursively loop before moving on to saving the capture image
function checkMore() {
//check to see if the 'read more' button exists
if (casper.exists('a.read-more')) {
//click the button to load more items
casper.click('a.read-more');
//wait for the items to load, then run the check again
casper.wait(3000, function() {
casper.run(checkMore);
});
}
}
casper.thenOpen(urls.details, function() {
//wait for the page along with ajax items to load shortly after
this.wait(3000, function() {
this.run(checkMore);
});
});
casper.then(function() {
//output the result
this.capture('output.jpg');
});
casper.run();
'실행'을 한 번만 호출해야한다고 생각합니다. wait 함수에 직접'checkMore'를 전달할 수 있습니다. 'this.wait (3000, checkMore)'. 그러나'checkMore'에서'this' 참조는 작동하지 않을 것입니다 - 그래서 당신은 eg를 써야합니다. 'casper.exists ('...')'. – pius
'read-more' 버튼을 기다리는 동안'waitForSelector'를 고려 했습니까? 이 시나리오에 적합한 것 같습니다. http://casperjs.readthedocs.org/en/latest/modules/casper.html#waitforselector – pius
어떻게 루프합니까? 문제가 무엇인지 설명하지 않았습니다. –