O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inspecting page content from a PhantomJS script

This recipe introduces webpage.evaluate, which provides us with a hook into the context and content of the web page we have requested, including ways to inspect and manipulate the DOM. The cornerstone for many of the recipes that lie ahead will be webpage.evaluate.

Getting ready

To run this recipe, we will need a script that loads a web page, and we will need a callback function to webpage.open that expects to work with the content of the HTTP response.

The script in this recipe is available in the downloadable code repository as recipe04.js under chapter03. If we run the provided example script, we must change to the root directory for the book's sample code. Lastly, for this example to work, we will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required