I'm working on a Perl script to get the "astronomy image of the day" and set it as my wallpaper. Then I would set a cronjob to do that everyday for me. But I'm having a hard time making the script follow the image link that leads to the full-sized image, and only then, download it. I was trying something like that code bellow(have in mind that I'm only a Perl beginner who does not know much about Perl regex):
#!/usr/bin/perl -w
use strict;
use warnings;
use WWW::Mechanize;
my $url = "http://apod.nasa.gov/apod/astropix.html";
my $mech = WWW::Mechanize->new();
$mech->get($url);
#debugging
if ($mech->follow_link(url_regex=>qr/\.(?:jpg|png)$/)){
print "Following the image link...";
}else{
print "Couldn't find the link...";
}
my @img = $mech->find_image(alt_regex => qr/image/i);
foreach my $img(@img){
$mech->get($img->url, ':content_file'=>'astro.jpg');
}
print "\n";
exit(0);
Any help would be much appreciated!