#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;

my $base = "http://www.dilbert.com";
my $baseurl = "http://www.dilbert.com/comics/dilbert/archive/dilbert-";
my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461)',
'cookie_jar' => {file => "lwpcookies.txt", autosave => 1} );

$start = 20060201; # first date in month..
do {
        $url = $baseurl.$start.".html";
        $res = $ua->request(GET "$url");
        my $html_recived = $res->as_string;
        my @ahtml = split ("\n", $html_recived);
        for (my $i = 0; $i <= $#ahtml; $i++)
        {
        # print $ahtml[$i]."\n";
                if ($ahtml[$i] =~ m#Today.s Dilbert Comic#i) {
                        if ($ahtml[$i] =~ m#SRC..(/comics/dilbert/[^\"]+)#i) {
                        print `wget $base$1`;
                        }
                }
}
$start++;
} while ($start < 20060217); # todays date

