Created
November 28, 2011 05:05
-
-
Save numberwhun/1399176 to your computer and use it in GitHub Desktop.
Script to download files with a specific extension from a specific URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use File::Basename; | |
use WWW::Mechanize; | |
my $mech = WWW::Mechanize->new(); | |
# Get the main page containing the urls. Modify the URL to the page you are going to grab from. | |
$mech->get( "http://url/with/files/to/grab.html" ); | |
$mech->success or die $mech->response->status_line; | |
# Modify the file extension to be the extension of the files to grab on the page in the link above. | |
my @links = $mech->find_all_links( url_regex => qr/\.jpg$/ ); | |
my @urls = map { $_->[0] } @links; | |
print("Found ", scalar @urls, " files to download...\n"); | |
#foreach(@links){ | |
# print("$_\n"); | |
#} | |
for my $url (@urls){ | |
my $filename = basename( $url ); | |
print("$filename ---> "); | |
$mech->get( $url, ':content_file'=>$filename ); | |
print -s $filename, " bytes\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment