1

I'm trying to access an https page using the WWW::Mechanize library in perl. Here's what I have:

#!/usr/local/bin/perl -w
use strict;
use lib '/home/perl_modules/libwww-perl-5.836/lib';
use lib '/home/perl_modules/WWW-Mechanize-1.72/lib';
use lib '/home/perl_modules/HTML-Tree-5.03/lib';
use lib '/home/perl_modules/Crypt-SSLeay-0.64/lib';
use WWW::Mechanize;

my $m = WWW::Mechanize->new();


my $url = "http://alumni.nd.edu";
my $alias = "Linux Mozilla";

$m->agent_alias($alias);

$m->follow_link(url => "/s/1210/start.aspx?sid=1210&gid=1&pgid=3&cid=40");

Here is the output:

Error GETing https://securelb.imodules.com/?sid=1210&gid=1&pgid=3&cid=40&returnurl=http%3a%2f%2falumni.nd.edu%2f: Server closed connection without sending any data back at www_mech_test.pl line 17

After reading some help pages about WWW::Mechanize, I tried setting an alias and including the Crypt-SSLeay module, but I'm still getting the above error. What am I missing? This is running under RHEL 5.5.

Alec
  • 1,178
  • 5
  • 20
user2150989
  • 233
  • 1
  • 7
  • 1
    off topic, but you should try [local::lib](http://search.cpan.org/dist/local-lib/lib/local/lib.pm) instead of a lot `use lib` – Alec Mar 09 '13 at 16:34
  • 1
    The following program works for me, takes about 100 seconds. (That IIS Web server is slow as molasses!) Upgrade [LWP](http://p3rl.org/LWP), [LWP::Protocol::https](http://p3rl.org/LWP::Protocol::https) and [IO::Socket::SSL](http://p3rl.org/IO::Socket::SSL) to the latest versions. `use WWW::Mechanize; my $m = WWW::Mechanize->new; $m->get('http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=3&cid=40'); print $m->content;` – daxim Mar 09 '13 at 18:38
  • @daxim: Could you please let me know what versions of each module you had to load to get it to work? I have the following loaded and it doesn't work: – user2150989 Mar 11 '13 at 15:15
  • @daxim: use lib '/home/perl_modules/libwww-perl-6.04/lib'; use lib '/home/perl_modules/WWW-Mechanize-1.72/lib'; use lib '/home/perl_modules/HTML-Tree-5.03/lib'; use lib '/home/perl_modules/Crypt-SSLeay-0.64/lib'; use lib '/home/perl_modules/LWP-Protocol-https-6.03/lib'; use lib '/home/perl_modules/IO-Socket-SSL-1.84/lib'; use lib '/home/perl_modules/HTTP-Message-6.06/lib'; use lib '/home/perl_modules/Encode-Locale-0.04/lib'; – user2150989 Mar 11 '13 at 15:16
  • @daxim: also what version of Perl are you using? – user2150989 Mar 11 '13 at 16:20
  • I'm using 5.10.1 and 5.16.2, but the Perl version does not matter. – You very likely are not installing the modules correctly, it looks like you are just unpacking the source archives. It doesn't work that way. Instead of what you are doing now, please use [local::lib](http://p3rl.org/local::lib) like Alec already said above. – From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [How can I install a CPAN module into a local directory?](http://stackoverflow.com/questions/540640/how-can-i-install-a-cpan-module-into-a-local-directory) – daxim Mar 11 '13 at 17:06
  • @daxim: Alright, I created a local lib in /home/perl5/lib/ and used CPAN to actually download and install all of the modules to that location. I'm still getting the same error, however. Here is my revised code: – user2150989 Mar 11 '13 at 19:54
  • @daxim: `#!/tool/bin/perl -w use strict; use local::lib; use WWW::Mechanize; use LWP::Protocol::https; use IO::Socket; my $m = WWW::Mechanize->new; $m->get('http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=3&cid=40'); print $m->content;` – user2150989 Mar 11 '13 at 19:55
  • @daxim: I was able to successfully run your program from my home machine running cygwin, so I'm almost positive the problem here has to do with the proxy server they are using from my work network. – user2150989 Mar 12 '13 at 14:43

1 Answers1

0

Your code isn't loading the page $url='http://alumni.nd.edu"'

Add this before the follow_link:

$m->get($url);
$m->follow_link(url => "/s/1210/start.aspx?sid=1210&gid=1&pgid=3&cid=40");

The follow_link call searches the document loaded by WWW::Mechanize, without it this isn't going to find anything.

Astuanax
  • 667
  • 5
  • 18