본문 바로가기
Linux

PhantomJS - Scriptable Headless Browser

by 코딩하는 미토콘드리아 bioinformatics 2024. 7. 12.
반응형

PhantomJS - Scriptable Headless Browser

 

https://phantomjs.org/

 

PhantomJS - Scriptable Headless Browser

PhantomJS - Scriptable Headless Browser Important: PhantomJS development is suspended until further notice (more details). PhantomJS is a headless web browser scriptable with JavaScript. It runs on Windows, macOS, Linux, and FreeBSD. Using QtWebKit as the

phantomjs.org

 

 

PhantomJS는 서버 측에서 웹 페이지를 사용할 수 있게 해주는 스크립트 가능한 헤드리스 웹킷(WebKit) 브라우저입니다. 쉽게 말해, GUI 없이 동작하는 웹 브라우저라고 할 수 있습니다.

PhantomJS는 JavaScript API를 통해 웹 페이지의 다양한 작업을 자동화할 수 있으며,

이를 통해 웹 스크레이핑, 웹 페이지 테스트, 스크린샷 생성 등 여러 작업을 수행할 수 있습니다.

주요 기능

  1. 웹 스크레이핑(Web Scraping): 웹 페이지에서 데이터를 추출하는 작업을 자동화할 수 있습니다.
  2. 웹 페이지 테스트: 테스트 프레임워크와 통합하여 웹 페이지의 기능을 테스트할 수 있습니다. (예: Selenium과 통합)
  3. 스크린샷 생성: 웹 페이지의 스크린샷을 찍어 이미지 파일로 저장할 수 있습니다.
  4. 페이지 자동화: 웹 페이지의 상호작용(폼 제출, 링크 클릭 등)을 자동화할 수 있습니다.
  5. 네트워크 모니터링: 웹 페이지의 네트워크 트래픽을 캡처하고 분석할 수 있습니다.

사용 예시

간단한 사용 예시로, PhantomJS를 사용하여 특정 웹 페이지의 스크린샷을 찍는 방법은 다음과 같습니다.

 

1. PhantomJS 설치

sudo apt-get install phantomjs

 

2. 스크린샷 찍기 스크립트 작성:

// screenshot.js
var page = require('webpage').create();
var system = require('system');
var url = system.args[1];

page.open(url, function(status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        phantom.exit();
    } else {
        window.setTimeout(function() {
            page.render('screenshot.png');
            phantom.exit();
        }, 200);
    }
});

 

3. 스크립트 실행

phantomjs screenshot.js http://example.com

 

이 스크립트는 http://example.com 웹 페이지를 열고 screenshot.png 파일로 스크린샷을 저장합니다.

 

 

 

github: https://github.com/ariya/phantomjs

 

GitHub - ariya/phantomjs: Scriptable Headless Browser

Scriptable Headless Browser. Contribute to ariya/phantomjs development by creating an account on GitHub.

github.com

 

반응형