in reply to Clicking a button with WWW::Mechanize

Hi again Anonymous Monk (and anyone else who may be able to help),

Having had a look at the links you've provided, I decided to give WWW::Mechanize::PhantomJS a try.

I installed the current version (0.06) on the commercial webhost that I use, using the cPanel webhosting control panel. The server is CentOS. I could not see any errors during the installation - it looked as if it installed OK. I then tried a couple of examples, including the first one at the top of the documentation page, and it fails. I then added warnings and strict, and here's the resulting code:

#!/usr/bin/perl -w use strict; use WWW::Mechanize::PhantomJS; my $mech = WWW::Mechanize::PhantomJS->new(); $mech->get('http://google.com'); $mech->eval_in_page('alert("Hello PhantomJS")'); my $png= $mech->content_as_png();
And here's the warning and error which result:
Can't exec "phantomjs": No such file or directory at /home/tel2/perl5/ +lib/perl5/WWW/Mechanize/PhantomJS.pm line 101. Couldn't launch [| phantomjs /home/tel2/perl5/lib/perl5/WWW/Mechanize/ +PhantomJS/ghostdriver/main.js --PhantomJS=8910 --logLevel=OFF]: No su +ch file or directory / 0 at /home/tel2/perl5/lib/perl5/WWW/Mechanize/ +PhantomJS.pm line 101.

Here is that section of code in PhantomJS.pm:

# Launch PhantomJs $options{ launch_exe } ||= 'phantomjs'; (my $ghostdir_default= __FILE__) =~ s!\.pm$!!; $ghostdir_default= File::Spec->catfile( $ghostdir_default, 'ghostd +river', 'main.js' ); $options{ launch_ghostdir } ||= $ghostdir_default; $options{ launch_arg } ||= []; push @{ $options{ launch_arg }}, "--PhantomJS=$options{ port }"; push @{ $options{ launch_arg }}, "--logLevel=\U$options{ log }"; my $cmd= "| $options{ launch_exe } $options{ launch_ghostdir } @{ +$options{ launch_arg } }"; #warn $cmd; $options{ pid } ||= open my $fh, $cmd or die "Couldn't launch [$cmd]: $! / $?";
The last line is line 101.

I've googled a bit for answers, but nothing yet. Any ideas what the problem is, or how to fix this?

Thanks again.
tel2

Replies are listed 'Best First'.
Re^2: Clicking a button with WWW::Mechanize
by choroba (Cardinal) on Aug 12, 2014 at 07:45 UTC
    Did you install phantom.js, too?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      No, choroba, I didn't realise it was a pre-requisite, but thanks for the pointer!

      I have now downloaded it from https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2, and temporarily extracted it to my local tmp directory.

      I can't see any installation instructions. The README.md file just says:
      "- **Easy to install**: {Download}(http://phantomjs.org/download.html), unpack, and start having fun in just 5 minutes."

      I haven't been able to find more installation instructions on the website.

      I assume I need to make it so WWW::Mechanize::PhantomJS can see & use it? How???

      If I run it from the command line, it seems to run, but I get a warning each time, e.g.:

      $ bin/phantomjs -h Fontconfig error: Cannot load default config file (and then I get the help listing)
      Any ideas about that? I saw it mentioned via Google, couldn't see an answer, yet.

      Thanks again.
      tel2