More Related Content Similar to Phantom js quick start Similar to Phantom js quick start (20) Phantom js quick start2. WTF
•
PhantomJS is a headless WebKit scriptable with
a JavaScript API. It has fast and native support
for various web standards: DOM handling, CSS
selector, JSON, Canvas, and SVG.
5. Screen Capture
1. var page = require('webpage').create();
2. page.open('http://wanggou.com', function() {
3.
page.render('wanggou.png');
4.
phantom.exit();
5. });
7. Evaluate Code
1. var page = require('webpage').create();
2. page.open(url, function(status) {
3.
var title = page.evaluate(function() {
4.
return document.title;
5.
});
6.
console.log('Page title is ' + title);
7. });
8. From: http://phantomjs.org/quick-start.html
9. Command-line Arguments
1. var system = require('system');
2. var args = system.args;
!
4. if (args.length === 1) {
5.
console.log('Try to pass some arguments when invoking this script!');
6. } else {
7.
8.
9.
10.}
args.forEach(function(arg, i) {
console.log(i + ': ' + arg);
});