노드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 파일이 저장되어 있다.
어떻게 사용할지 응용은 각자 알아서 하면 될 것이다.
'nodejs' 카테고리의 다른 글
| nodejs: 네이버지식인 포스팅 예제 (0) | 2023.11.09 |
|---|---|
| nodejs: express index.js 간단한 예제 (0) | 2023.11.09 |
| nodejs: 웹페이지 리스트 파싱 예제 (0) | 2023.11.09 |
| nodejs: cheerio 웹페이지 TABLE 크롤링하여 파일 저장 예제 (0) | 2023.11.09 |
| nodejs: express 실행 간단한 예제 (0) | 2023.11.09 |