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

Opening a URL within PhantomJS

This recipe expands on the webpage object and introduces its open method. Here, we will focus on the basic version of open, which takes a URL and a simple callback function.

Getting ready

To run this recipe, we will need a script that accesses a web page. For this example to complete, an Internet connection is also required.

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

How to do it…

Consider the following script:

var webpage = require('webpage').create(); webpage.open('http://blog.founddrama.net/', function(status) { switch (status) { case 'success': console.log('webpage ...

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