Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Wednesday March 23, 2005
07:16 PM

Today's Mech trick

[ #23813 ]

There's a batch of really gorgeous images released under the Creative Commons license at http://draves.org/pix/kdn/; the following code fetches all of them (slowly) at their maximum resolution.

Max resolution is big - 2 to 8 MB each. These are seriously detailed pictures. I added a 5-minute pause between fetches to be polite.

use strict;
use WWW::Mechanize;
my $mech = new WWW::Mechanize;
my $image_mech = new WWW::Mechanize;
my $base = "http://draves.org/pix/frame3.cgi?dir=kdn&file=acanthametra/big%20two%20spike%20 star%20copy.png&zoom=0";
 
my $current = $base;
$mech->get($current);
 
while (1) {
  my ($image) = (($mech->content) =~ /img .* src="([^"]+)/s);
  $image=~ s/ /%20/g;
  $image_mech->get("http://draves.org/pix/$image");
  print $image,"\n";
  my ($dir,$name) = ($image =~ m{^(.*/)(.*)$});
  system "mkdir -p $dir";
  open PIX, ">$image" or die "Can't open $image: $!";
  print PIX $image_mech->content;
  close PIX;
  sleep 300;
  $mech->follow_link('text'=>'next');
  last unless $mech->success;
}

Strictly utilitarian, but it gets the job done, and lets me have truly bizarro desktop graphics, thich is nice. I'm realizing that the 'next' link will probably crap out when it gets to the last page, but that's not a big deal since I want to stop at that point anyway.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.