//모든 스텝은 해당 시간만큼 웨이팅후 종료

casper.options.waitTimeout = 20000;


//캐스퍼의 시작

casper.start();


//캐스퍼의 실행

//해당 문구는 꼭 존재해야한다.

casper.run();


//앞에 스텝의 캐스퍼를 실행 종료된후에 다음순서로 실행..

casper.then();


//새롭게 창을 오픈

 casper.thenOpen(url);


//로그인 하기

this.fill('form[name="FormLogin"]', {

 'member_id': 'testID',

 'member_pwd': 'qwer1234'

}, true);



// 주의할점

// 2번째로 실행했을때는 setInterval 때 반복되지 않고 한번만 실행된다.


casper.run();


casper.run(function() {

    casper.close();

});


//엘리먼트 존재여부 확인 exists ()

casper.start('http://foo.bar/home', function() {

    if (this.exists('#my_super_id')) {

        this.echo('found #my_super_id', 'INFO');

    } else {

        this.echo('#my_super_id not found', 'ERROR');

    }

});


// HTML 내용 가져오기

var bc_1 = this.getHTML('#bc_1');


// 텍스트 내용만 가져오기

casperjs.fetchText('td.detail_line:first');


//버튼 클릭

casper.click('input.btn_bet_a:nth-child(3)');


//화면 캡쳐

 casper.capture('test.png');


//로그인 후 쿠키 저장 및 불러오기

var cookies = JSON.stringify(phantom.cookies);

fs.write(cookie_path, cookies, 'w');

phantom.cookies = JSON.parse(fs.read(cookie_path));



// 2초간 기다리기

casper.wait(2000, function() {

                casper.click('input.btn_bet_b');

                casper.capture('sutda.png');

});


// login_list 클래스가 존재할때까지 기다리기

this.waitForSelector('.login_list', function() {


});


// 알람창이 뜰때까지 기다리기

casper.waitForAlert(function(response) { 


});

'크롤링' 카테고리의 다른 글

캐스퍼 url 접속 여부 테스트  (0) 2017.03.13
원하는 패턴 문자열 뽑기  (0) 2017.02.07
fetchText 와 getHTML 차이  (0) 2016.10.29
쿠키 파일로 저장  (0) 2016.09.22
블로그 이미지

칩사마코더

,