본문 바로가기

nodejs

nodejs: 웹사이트 화면캡쳐 screenshot.js

노드JS를 이용하여 웹사이트 화면캡쳐를 해보는 예제이다.

puppeteer 모듈이 필요하고, 다음(daum) 사이트 첫 화면을 캡쳐하여

JPG 스크린샷으로 정해진 폴더에 저장하는 부분까지이다.

 

screenshot.js

const puppeteer = require('puppeteer');
const timeOut = 100 * 1000;

puppeteer.launch({
    headless: true,
    slowMo:30,
    args: ['--window-size=800x600', '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--disable-gpu']
}).then(async browser=> {
    const page = await browser.newPage();
    await page.setRequestInterception(false);
    await page.goto('http://daum.net', {waitUntil:'networkidle2', timeout:25000});
    await page.screenshot({path: '/tmp/daum.jpg'});
	await page.close();
    await browser.close();
});

 

D:\nodejs>node screenshot.js

 

d:/tmp 폴더에 들어가 보니까, daum.jpg 파일이 저장되어 있다.

어떻게 사용할지 응용은 각자 알아서 하면 될 것이다.