0
votes

I just imported WWW::Mechanize::PhantomJS today that appeared to be successful using cpan WWW::Mechanize::PhantomJS. After the completion of the install/import, I used the default example program as a test and received this error:

'phantomjs' is not recognized as an internal or external command Question: How do I fix this problem?

This error is coming from this line in the test program:

my $mech = WWW::Mechanize::PhantomJS->new(
    launch_arg => ['ghostdriver/src/main.js' ],
);

Here is the full code copied directly from the PhantomJS example code:

use strict;
use File::Spec;
use File::Basename 'dirname';
use WWW::Mechanize::PhantomJS;
my $url = 'https://radioa1a.com/trop-40-vote/';

my $mech = WWW::Mechanize::PhantomJS->new(
    launch_arg => ['ghostdriver/src/main.js' ],
);

sub show_screen() {
   my $page_png = $mech->content_as_png();
    my $fn= File::Spec->rel2abs(dirname($0)) . "/screen.png";
    open my $fh, '>', $fn
    or die "Couldn't create '$fn': $!";
    binmode $fh, ':raw';
    print $fh $page_png;
    close $fh;




    #system(qq(start "Progress" "$fn"));
};

$mech->get($url);

show_screen;

The full error message from my Windows 10 command prompt window:

C:\Users\Bryon\Desktop\Perl>TestWebPage.pl
'phantomjs' is not recognized as an internal or external command,
operable program or batch file.
Selenium server did not return proper status at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 543.

C:\Users\Bryon\Desktop\Perl>

My environment:

  1. Windows 10 64-bit
  2. Strawberry Perl version:

    C:\Users\Bryon\Desktop\Perl>perl -v

    This is perl 5, version 30, subversion 2 (v5.30.2) built for MSWin32-x64-multi-thread

    Copyright 1987-2020, Larry Wall

    Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit.

    Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Also, I see the PhantomJS module components in the C:\strawberry\perl\site\lib\wWW\Mechanize\PhantomJS\

So how do I fix this issue?

Thank you in advance for your help

1
Sounds like you need to install phantomjs and/or have it in your path.Red Cricket
Yes, you need the PhantomJS executable on your OS. But it's an abandoned software (since 2018). Better learn to code in javascript with chrome headless+puppeteer module. When you know the basics, it's not that hard to learnGilles Quenot
Found an unofficial Python port: github.com/miyakogi/pyppeteer (nothing for Perl). I don't recommend this specific wayGilles Quenot
Yes phantomjs is not being maintained anymore. But I still use it :)Red Cricket
The module relies on the phantomjs tool, which needs to be installed and in your PATH. Note that development of phantomjs was abandoned two years ago.ikegami

1 Answers

0
votes

XXXXX is not recognized as an internal or external command, operable program or batch file.

This error tells that there is no needed executable in your PATH.
Try to download actual PhantomJS executables for windows from official site and place it into folder from your PATH variable.