DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

ImgShack Scraper

08.18.2008
| 4361 views |
  • submit to reddit
        // Scrapes the given imgshack server for uploaded images.  Change the img219 to a different number for different results.

#!/usr/bin/perl -w
#use strict;
use WWW::Mechanize;
use WWW::Mechanize::Link;

#Create an Object
my $mech = WWW::Mechanize->new();
my $a;
print "hello";
$a = 1;
while ($a <= 999) {
print "$a";
#Url to search images on.
my $url = "http://img219.imageshack.us/my.php?image=$a.jpg";
print "$url";
#Request webpage
$mech->get( $url );
#Find image
my @imglinks = $mech->find_image( alt_regex => qr/^img/i);
foreach my $currentimg (@imglinks) {
        #Get image
        $mech->get( $currentimg->url_abs, ":content_file" => "$a.jpg");
}
print "\n";
$a++;
}