#!/bin/perl -w use URI; use LWP; use HTTP::Cookies; use Switch; chdir '/home/medlir/download/shared/rlc'; my $num = $ARGV[0]; my $url = ''; my $httpRes = ''; my @html = (); my $year = 1999; my $month = 'November'; my $monthnum = 11; my $day = 15; my $imgurl = ''; print "\n"; my $ua = LWP::UserAgent->new(); $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050516 Firefox/1.0.4 (MOOX M3)'); $ua->cookie_jar(HTTP::Cookies->new(file => "/home/medlir/download/shared/rlc/.cookies", autosave => 1)); while ($num <= $ARGV[1]) { print 'Downloading strip '.$num.': '; $url = 'http://www.reallifecomics.com/daily.php?strip_id='.$num; $httpRes = $ua->request(HTTP::Request->new (GET => $url)); @html = split(/\n/,$httpRes->content); foreach (@html) { if ($_ =~ /
\w+ - (.*?) (\d+), (\d+)<\/div>/) { $month = $1; $day = $2; $year = $3; # print "\n".'Success! Year: '.$year.' Month: '.$month.' Day: '.$day."\n"; next; } elsif ($_ =~ /
<\/div>/) { $imgurl = 'http://www.reallifecomics.com/daily.php'.$1; # print 'Image URL: '.$imgurl."\n"; last; } } print 'done! Downloading image... '; switch ($month) { case "January" { $monthnum = '01'; } case "February" { $monthnum = '02'; } case "March" { $monthnum = '03'; } case "April" { $monthnum = '04'; } case "May" { $monthnum = '05'; } case "June" { $monthnum = '06'; } case "July" { $monthnum = '07'; } case "August" { $monthnum = '08'; } case "September" { $monthnum = '09'; } case "October" { $monthnum = '10'; } case "November" { $monthnum = '11'; } case "December" { $monthnum = '12'; } else { $monthnum = '--'; } } while (length("$day") < 2) { $day = '0'.$day; } # print 'Month Num: '.$monthnum."\n"; # print '"'.$year.$monthnum.$day.'.png"'."\n"; system('wget -q -O "'.$year.$monthnum.$day.'_'.$num.'.png" "'.$imgurl.'"'); if ($? != 0) { print 'FAILED! Status: '.$?."\n"; system('echo "'.$num.' - '.$?.'" >> errors.log'); } else { print 'done!'."\n"; } $num++; sleep 1; } exit 0; sub timeString { my ($sec,$min,$hrs,$day,$mon,$year) = localtime(time); $year += 1900;$mon += 1; $mon = '0'.$mon if length($mon) < 2; $day = '0'.$day if length($day) < 2; $hrs = '0'.$hrs if length($hrs) < 2; $min = '0'.$min if length($min) < 2; $sec = '0'.$sec if length($sec) < 2; return '['.$hrs.':'.$min.':'.$sec.'] '; }