0
PhantomJs Quick Start
@laserji 2013-12-06 44ux.com
WTF

•

PhantomJS is a headless WebKit scriptable with
a JavaScript API. It has fast and native support
for various web st...
WFT
•

HEADLESS WEBSITE TESTING

•

SCREEN CAPTURE

•

PAGE AUTOMATION

•

NETWORK MONITORING
Install

•

DOWNLOAD && INSTALL
Screen Capture
1. var page = require('webpage').create();
2. page.open('http://wanggou.com', function() {
3.

page.render(...
Screen Capture
•

Capture part of the page

1. page.clipRect = { top: 20, left: 20, width: 200,
height: 200};
2. page.rend...
Evaluate Code
1. var page = require('webpage').create();
2. page.open(url, function(status) {
3.

var title = page.evaluat...
Inject Script
1. if(page.injectJs('jquery.js')){
2.
3. }

// use $
Command-line Arguments
1. var system = require('system');
2. var args = system.args;

!
4. if (args.length === 1) {
5.

co...
END

•

More: http://phantomjs.org/
Upcoming SlideShare
Loading in...5
×

Phantom js quick start

1,050

Published on

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,050
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Phantom js quick start"

  1. 1. PhantomJs Quick Start @laserji 2013-12-06 44ux.com
  2. 2. 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.
  3. 3. WFT • HEADLESS WEBSITE TESTING • SCREEN CAPTURE • PAGE AUTOMATION • NETWORK MONITORING
  4. 4. Install • DOWNLOAD && INSTALL
  5. 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. });
  6. 6. Screen Capture • Capture part of the page 1. page.clipRect = { top: 20, left: 20, width: 200, height: 200}; 2. page.render('wanggou.png');
  7. 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
  8. 8. Inject Script 1. if(page.injectJs('jquery.js')){ 2. 3. } // use $
  9. 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); });
  10. 10. END • More: http://phantomjs.org/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×