2017년 11월 3일 금요일

casperjs 팁

casperjs 로 대여섯개 사이트 자동 출첵을 걸어놨다.

삽질 중에 얻은 팁을 공유한다.

 

1. <input> 에 type 이 없을 경우 fill 이 안 먹힘. << 이런 개 같은 경우가 있음  그럴 때는 sendKey를 활용.

2. alert 한글이 깨지는 경우 setting 옵션에 encoding: "utf8", 를 넣으면 됨.

3. verbose: true로 해야 syntax 에러 나옴.

4.onsubmit="INVEN.Outlogin.login(this); return false;"   << 이런식으로 되어 있으면 fill true 가 제대로 동작 안함. click 이벤트로 처리 하도록

(INVEN이네..;;)

 

11번가 처리시
5. iframe 처리iframe접근은 casper.withFrame 를 사용.

 
==================
[debug] [phantom] opening url: http://www.11st.co.kr/browsing/NewPlusZonePlace.tmall?method=getEventPage&addCtgrNo=951965, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.11st.co.kr/browsing/NewPlusZonePlace.tmall?method=getEventPage&addCtgrNo=951965, type=Other, willNavigate=true, isMainFrame=true << isMainFrame이 true
[debug] [phantom] url changed to "http://www.11st.co.kr/browsing/NewPlusZonePlace.tmall?method=getEventPage&addCtgrNo=951965"
[debug] [phantom] Navigation requested: url=http://www.11st.co.kr/html/blank.html, type=Other, willNavigate=true, isMainFrame=false << isMainFrame이 false임. iframe이란 소리.
[debug] [phantom] Navigation requested: url=http://www.11st.co.kr/jsp/event15/150625_benefitZoneAttend/iframe.jsp, type=Other, willNavigate=true, isMainFrame=false << iframe
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false << iframe
[debug] [phantom] Navigation requested: url=https://vars.hotjar.com/rcj-99d43ead6bdf30da8ed5ffcb4f17100c.html, type=Other, willNavigate=true, isMainFrame=false << iframe
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 5/8 http://www.11st.co.kr/browsing/NewPlusZonePlace.tmall?method=getEventPage&addCtgrNo=951965 (HTTP 200)
[info] [phantom] Step anonymous 5/8: done in 6937ms.
[info] [phantom] Step _step 6/8 http://www.11st.co.kr/browsing/NewPlusZonePlace.tmall?method=getEventPage&addCtgrNo=951965 (HTTP 200)
[info] [phantom] Step _step 6/8: done in 6955ms.
==================

위의 로그를 보면 iframe이 4개임.
iframe 이름이 있으면 casper.withFrame('이름'... 이런식으로 주지만, 이름이 없으면 0부터 index를 준다.

댓글 1개: