user227668
user227668

Reputation: 41

Error while using WWW::Mechanize in Perl to open a Webpage

I am trying to open a web page in Perl using WWW::Mechanize module. The code for the same is as follows:

use WWW::Mechanize;
my $m = WWW::Mechanize->new();
$url = 'http://www.google.com';
$m->get($url);
print "$m->content()";

When i run this code i get an error like this: Error GETing http://www.google.com :Can't connect to www.google.com:80. What could be the reason for such an error and how can I change my code so that it opens up the webpage specified in the URL.?

Upvotes: 1

Views: 104

Answers (1)

Gilles Quénot
Gilles Quénot

Reputation: 185053

There's 2 problems :

  1. the line print "$m->content()"; should be written print $m->content(); : you will get WWW::Mechanize=HASH(0xeca870)->content() otherwise.

  2. it seems that you have a network or software problem: the rest of your code works.

Upvotes: 2

Related Questions