Created
May 29, 2015 22:46
-
-
Save justindisney/7914ab63981f4a75d191 to your computer and use it in GitHub Desktop.
Render a single DOM element using PhantomJS
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
/* | |
* renderDomElement.js | |
* An example of how to render a single DOM element using PhantomJS 2.0 | |
*/ | |
var system = require('system'); | |
if (system.args.length != 4) { | |
console.log('Usage: phantomjs renderDomElement.js <url> <class-selector> <output-file>'); | |
phantom.exit(); | |
} else { | |
var page = new WebPage(); | |
var url = system.args[1]; | |
var selector = system.args[2]; | |
var outputFile = system.args[3]; | |
page.open(url, function (status) { | |
if (status == 'success') { | |
page.clipRect = page.evaluate(function (selector) { | |
return document.querySelector(selector).getBoundingClientRect(); | |
}, selector); | |
page.render(outputFile); | |
} | |
phantom.exit(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple and useful. Thanks!