Skip to main content
use LWP;
use URI::Escape;
use File::Basename;
use File::Path qw(make_path);
$url = 'samplesamle.com/sample';
my $browser = LWP::UserAgent->new;
my $response = $browser->get($url);
die "Can't get $url -- ", $response->status_line unless $response->is_success;
my $html = $response->content;
#print "Html--> ".$html."\n";
while($html =~ /(<a href="\/(([^\;]+).pdf);)/igs){
$image_name = $2;
# print "Image--> ".$image_name."\n";
$image_full = $url."".$image_name;
my $browser1 = LWP::UserAgent->new;
my $response1 = $browser1->get($image_full);
#my $html1 = $response1->content;
my ($name,$path,$suffix) = fileparse($image_full);
# print "p--> ".$path."\n";
$path =~ s/^(http|src):\/\///igs;
make_path($path);
#print "->".$html."\n" unless($response->is_error);
&file_write("$path/$name",$response1);
}
sub file_write(){
$_file = shift;
$_data = shift;
print $_data."\n\n\n";
open (DATA_FILE,">>$_file") or die("Cannot open a file $_file ->$!\n");
binmode(DATA_FILE);
print DATA_FILE "$_data";
close(DATA_FILE);
}
Comments
Post a Comment