Monday, May 29, 2006

Extract links from a file [perl]

How to extractlinks from a file

#!/usr/bin/perl
use HTML::SimpleLinkExtor;
my $file = new HTML::SimpleLinkExtor();

# Extracts Links from a HTML File
# Written by Vaibhav Gupta guptav@cse.iitb.ac.in
$filename = $ARGV[0];
$url = $ARGV[1]; #base url else empty string

if($filename eq "" ) {
print "\nUsages: ./extractlink.pl filename.html\n";
exit ;
}

$file->parse_file($filename);
my @links= $file->a;
foreach $link (@links){
chomp;
print "$url$link\n";
}