Save link to file : HTML Parser « Network « Perl





Save link to file

    

use LWP::Simple;
require HTML::Parser;

require HTML::LinkExtor;

$html = get("http://www.google.com");

$link_extor = HTML::LinkExtor->new(\&handle_links);

$link_extor->parse($html);

sub handle_links 
{

     ($tag, %links) = @_;

     if ($tag = 'a href' && $links{href} ne '') {

        $url = $links{href};

        $file = $url;
        $file =~ s/http:\/\/www\.//;
        $file =~ s/http:\/\///g;
        $file =~ tr/\//-/;

        print "Creating $file.\n";

        mirror ($url, $file);
     };
}

   
    
    
    
  










Related examples in the same category

1.Extract link from a web page