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:
Import the
webpage
module and assign it to a variable with that name, using the following command:phantomjs> var webpage = require('webpage'); undefined
Create an instance of a
webpage
object from the module, using the following command:phantomjs> var thePage = webpage.create(); undefined
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...