Created
January 30, 2017 13:22
-
-
Save hamrammi/d5e058c7a1707912ca1762be086e306c to your computer and use it in GitHub Desktop.
PhantomJS capture webpage command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var page = require('webpage').create(); | |
var system = require('system'); | |
page.viewportSize = { width: 1024, height: 768 }; | |
page.clipRect = { top: 0, left: 0, width: 1024, height: 768 }; | |
var url = system.args[1]; | |
var time = Date.now() | |
function extractDomain (url) { | |
var domain; | |
if (url.indexOf("://") > -1) { | |
domain = url.split('/')[2]; | |
} else { | |
domain = url.split('/')[0]; | |
} | |
domain = domain.split(':')[0]; | |
return domain; | |
} | |
var domain = 'offer_images/' + extractDomain(url) + '_' + time | |
page.open(url, function (status) { | |
if (status === 'success') { | |
page.evaluate(function () { | |
var style = document.createElement('style'), | |
text = document.createTextNode('html, body { background-color: #ffffff }'); | |
style.setAttribute('type', 'text/css'); | |
style.appendChild(text); | |
document.head.insertBefore(style, document.head.firstChild); | |
document.body.style.backgroundColor = '#ffffff'; | |
}); | |
page.render(domain + '.png'); | |
} | |
console.log(domain) | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment