Skip to content

Instantly share code, notes, and snippets.

@lisysolution
Created November 5, 2016 14:43
Show Gist options
  • Save lisysolution/040765f968a2484e91f3dfebaa31eaa4 to your computer and use it in GitHub Desktop.
Save lisysolution/040765f968a2484e91f3dfebaa31eaa4 to your computer and use it in GitHub Desktop.
PhantomJS를 이용하여 웹 사이트 스크린샷 저장하기
// http://phantomjs.org/
var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 480 };
page.open('http://www.naver.com/', function (status) {
if (status !== 'success') {
console.log('Unable to access the network!');
} else {
sleep(30000);
page.evaluate(function () {
var body = document.body;
body.style.backgroundColor = '#fff';
// 특정 항목을 가리고 싶은 경우.
// body.querySelector('div#id-name').style.display = 'none';
});
page.render('snap.png');
}
phantom.exit();
});
function sleep(num){
var now = new Date();
var stop = now.getTime() + num;
while(true){
now = new Date();
if(now.getTime() > stop) return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment