Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Weather RSS image

by pg (Canon)
on Nov 09, 2005 at 21:46 UTC ( #507224=note: print w/replies, xml ) Need Help??

in reply to Weather RSS image

Looks like there are only 48 images there, and the following code should grab all of them for you.

use LWP::UserAgent; use strict; use warnings; my $ua = LWP::UserAgent->new(); for my $index (0 .. 47, 3200) { print "downloading $index.gif\n"; my $res = $ua->get("$ +index.gif"); if ($res->is_success) { open GIF, ">", "weather$index.gif"; binmode(GIF); print GIF $res->content; close(GIF); } }

Update: Added 3200.gif, as ikegami pointed out.

Replies are listed 'Best First'.
Re^2: Weather RSS image
by davidrw (Prior) on Nov 09, 2005 at 21:58 UTC
    (above caveats on harvesting the images) but just for sake of example here's a bash one liner:
    for n in `seq 0 99` ; do wget +/we/52/$n.gif ; done
    Also, instead of get() and open/print/close, can just use LWP::Simple's getstore() method:
    use LWP::Simple; use strict; use warnings; for my $index (0 .. 99) {# actually 47 is the last index print "downloading $index.gif\n"; my $res = getstore("$ +index.gif", "weather$index.gif"); }
    or just:
    perl -MLWP::Simple -e 'getstore(" +s/we/52/$_.gif", "weather$_.gif") for 0 .. 99'

      Unfortunately your Perl code does not work. I called binmode() in my code for a reason. Your code would be fine with html files, but with images, it does not work.

      If you test your code, you will see that some images are broken (or cannot be recognized as the right format).

        Huh? getstore calls binmode:

        elsif (!ref($arg)) { # filename open(OUT, ">$arg") or return HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERV +ER_ERROR, "Cannot write to '$arg': $!"); binmode(OUT);


        Call stack:

        • LWP::Protocol::collect
        • LWP::Protocol::http::request
        • LWP::UserAgent::send_request
        • LWP::UserAgent::simple_request
        • LWP::UserAgent::request
        • LWP::Simple::getstore

        It's not a recent addition either. The version of libwww-perl packaged with ActiveState Perl v5.6.1 does the same thing.

        I've successfully downloaded all the images on a Windows system (where binmode would matter) using getstore and ActiveState Perl v5.6.1.

        It does work (well, i had to do s/Sumple/Simple/ first ;) ) -- and running file weather* afterward shows "GIF image data, version 89a, 52 x 52" for all of them ...
        which images did you see as broken? Did you try re-downloading them?
Re^2: Weather RSS image
by ikegami (Pope) on Nov 09, 2005 at 22:04 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://507224]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2020-10-23 11:18 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (238 votes). Check out past polls.