programming-examples/perl/Network/Save link to file.pl

30 lines
539 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
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);
};
}