I’m able to grab the first image fine, but then the content seems to be looping inside itself. Not sure what I’m doing wrong.
#!/usr/bin/perl
use LWP::Simple;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
for(my $id=1;$id<55;$id++)
{
my $response = $ua->get("http://www.gamereplays.org/community/index.php?act=medals&CODE=showmedal&MDSID=" . $id );
my $content = $response->content;
for(my $id2=1;$id2<10;$id2++)
{
$content =~ /<img src="http:\/\/www\.gamereplays.org\/community\/style_medals\/(.*)$id2\.gif" alt=""\/>/;
$url = "http://www.gamereplays.org/community/style_medals/" . $1 . $id2 . ".gif";
print "--\n\r";
print "ID: ".$id."\n\r";
print "ID2: ".$id2."\n\r";
print "URL: ".$url."\n\r";
print "1: ".$1."\n\r";
print "--\n\r";
getstore($url, $1 . $id2 . ".gif");
}
}
As others have stated, this is really a job for an HTML::Parser. Also, you should ‘use strict;’ and remove use LWP::Simple as you’re not using the library.
You could change your regex to the following:
But you won’t get style_medals/comp_graphics_10.gif – which may be what you want. I think something like the following would work better. My apologies for the style changes but I can’t resist modifying for PBP.