Book Image

PhantomJS Cookbook

By : Rob Friesel
Book Image

PhantomJS Cookbook

By: Rob Friesel

Overview of this book

Table of Contents (15 chapters)
PhantomJS Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a web page instance in PhantomJS with the webpage module


This recipe introduces the webpage module and demonstrates how to create an instance of a webpage object.

Getting ready

To run this recipe, we will simply create an instance of a webpage object; we can do this in the REPL.

Tip

See the Launching the PhantomJS REPL recipe in Chapter 1, Getting Started with PhantomJS, for more information about the REPL.

How to do it…

After entering the PhantomJS REPL, perform the following steps:

  1. Import the webpage module and assign it to a variable with that name, using the following command:

    phantomjs> var webpage = require('webpage');
    undefined
    
  2. Create an instance of a webpage object from the module, using the following command:

    phantomjs> var thePage = webpage.create();
    undefined
    
  3. Loop through the properties on the webpage instance and print them out, using the following command:

    phantomjs> for (var p in thePage) console.log(p);
    objectName
    title
    frameTitle
    content
    frameContent
    # and 88 more...