5% assure discount from here only

Saturday, February 5, 2011

(20) How to get html content of a site?

Solution :

I love to do programming in PERL because of so many reasons, out of them one is to get content of a site is very easy. You can get any site content by using the following script.

For running this script the only thing you should have is cpan module named WWW::Mechanize which can be easily downloaded from search.cpan.org or can be installed from you machine by typing following command on terminal

$ su -
#Enter your root password

cpan WWW::Mechanize

#!/usr/bin/perl -w

use strict;
use WWW::Mechanize;

### Enter url like (http://www.facebook.com) ###

print "Enter the URL\n";
my $url = <>;

my $mech = WWW::Mechanize->new;
$mech->get($url);

print $mech->content();

1 comment:

  1. Please don't encourage people to use indirect object notation. It can lead to hard to find bugs.

    my $mech = WWW::Mechanize->new;

    Also, you probably need to 'chomp' the URL that you've read from STDIN. It probably doesn't matter in this case, but not chomping your input is a bad habit to get into.

    ReplyDelete