我遇到了一个问题。我想使用WWW :: Mechanize :: PhantomJS。我将其设置如下。1.安装Strawberry和WWW :: Mechanize :: PhantomJS模块。2.下载PhantomJS zip,解压缩并设置phantomjs可执行文件的路径。3.创建了一个示例脚本,如下所示:
BEGIN{ $ENV{HTTPS_PROXY} = 'http://myproxyserver:port'; $ENV{HTTP_PROXY} = 'http://myproxyserver:port'; } use WWW::Mechanize::PhantomJS; use Data::Dumper; my $mech = WWW::Mechanize::PhantomJS->new(); $mech->get('http://google.com'); print Dumper $mech->content();
但是当我执行此脚本时,出现以下错误:
Selenium server did not return proper status at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 395.
我缺少什么。我假设此WWW :: Mechanize :: PhantomJS从环境中指定的路径启动phantomjs。
编辑:我卸载了WWW :: Mechanize :: PhantomJS并尝试再次安装,但得到以下输出:
t/00-load.t ................... ok t/49-mech-get-file.t .......... # Testing with C:\bin\phantomjs\phantomjs.exe Selenium server did not return proper status at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 395. # Looks like your test exited with 9 before it could output anything. t/49-mech-get-file.t .......... Dubious, test returned 9 (wstat 2304, 0x900) Failed 12/12 subtests t/49-mech-nav.t ............... # Testing with C:\bin\phantomjs\phantomjs.exe Selenium server did not return proper status at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 395.
然后按照建议,我修改了C:\ Strawberry \ perl \ vendor \ lib \ LWP \ Protocol \ http.pm,如下所示
sub _new_socket { my($self, $host, $port, $timeout) = @_; # IPv6 literal IP address should be [bracketed] to remove # ambiguity between ip address and port number. if ( ($host =~ /:/) && ($host !~ /^\[/) ) { #$host = "[$host]"; $host = '127.0.0.1'; }
并再次发出命令cpan WWW :: Mechanize :: PhantomJS,但再次输出相同。