Programming
No. 748
Name. swindler
Subject. PhantomJS
Main Cate. Javascript
Sub Cate. 개발일반
Date. 2014-01-17 18:58
Hit. 3720 (211.36.2...)
File. phantomjs-logo.png    capture_1.png  
http://phantomjs.org/

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

QT기반의 WebBrowser를 이용해 웹페이지를 로딩하여 javascript, dom 객체등을 컨트롤 할 수 있다.
이것을 전부 javascript로 처리할 수 있고, nodejs용 라이브러리도 제공된다.


아래와 같은 형태로 naver 페이지 캡쳐도 할 수 있다.
실행은 phantomjs snap.js 로 한다.

snap.js

var page = require('webpage').create();

page.open('http://www.naver.com', function () {
window.setTimeout(function(){
page.render('capture.png');
phantom.exit();
},3000);
});





설치하기.
http://phantomjs.org/download.html 에서 OS에 맞는 파일을 다운받으면 된다.

Linux 버전을 사용하는데, 친절하게도 Qt, WebKit or any other library 설치가 필요없다고 한다. ㅎㅎ

다운받은 파일만 압축풀고
위 예제를 실행하니까 바로 끝이다 ^^


여기 첨부된 이미지가 지금 막 캡쳐한 네이버 화면이다. (크기만 약간 줄였다.)
이게 과연 실제 브라우저와 얼마나 차이가 존재하는지는 모르겠다.



캡쳐를 예로 든것이 phantom.js의 유용한 기능중 하나라서 그런것이고,
앞에 설명한 것처럼 페이지를 로딩하여 javascript, dom, css 등을 핸들링 할수 있으므로, 테스트자동화등에도 많이 사용된다.

실제로 공식 홈페이지에는 아래와 같은 Feature가 나와 있다.

- Headless Website Testing
- Screen Capture
- Page Automation
- Network Monitorin



[바로가기 링크] : http://coolx.net/cboard/develop/748



Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox