Phantomjs fails on Amazon EC2 (Ubuntu 12.04 AMI)

amazon ec2phantomjsubuntu-12.04

I'm trying to run Phantomjs (most specifically Casperjs) on a Amazon EC2, using Ubuntu latest image (12.4).
To be sure, I tried with two different builds. One compiled on my dev machine (Phantomjs 1.6.0) and another built in the EC2 itself (Phantomjs 1.6.1).

Both with same results:
The connection doesn't happen.

Using the pizza example:

I can

wget 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search'

and I get the requested page, but when I run

phantomjs examples/pizza.js

I get

Unable to access network.

There are no rules active on iptables.

Any hints on what might be causing that?
Or what should I do to get more details about the issue?

Thanks.

Best Answer

In that example, the Phantom script will throw "unable to access network" if the request doesn't return 'success'. In fact, a request to the URL in your example returns a 301 'moved permanently' and redirects back to yelp.com/search. I believe the example is outdated and Yelp have since updated their website UI.

Url format is now: http://www.yelp.com/search#find_desc=pizza&find_loc=San+Francisco&show_filters=1

And the address now sits in an <address> element.

Update the url and the selector to something like:

document.querySelectorAll('address')

Also,the example script you've linked to is for Phantom 1.2. The following is deprecated:

var page = new WebPage();

And replaced by the following in newer versions:

var page = require('webpage').create();

Same example for Phantom 1.6. Remember to update the url and selector: http://code.google.com/p/phantomjs/source/browse/examples/pizza.js?name=1.6

Related Topic