Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Weather RSS image

by mikey19661 (Initiate)
on Nov 09, 2005 at 20:57 UTC ( #507207=perlquestion: print w/replies, xml ) Need Help??
mikey19661 has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to incorporate images from: into my site. Yet I don't know exactly how to grab the images out of there, for I don't have much experience with perl. Could anyone point me to a location where I can learn more on how to do this, or are there any modules that can grab these images for me?

Replies are listed 'Best First'.
Re: Weather RSS image
by InfiniteSilence (Curate) on Nov 09, 2005 at 21:15 UTC
    Uh, I don't think you want to grab images from someone else's site to incorporate in your own. That kind of thing typically incites a 'cease and desist' letter from an unfriendly legal department.

    I think what you want is their RSS Feed (technically you are not supposed to re-use that either, but don't tell anybody I told you). Just use XML::Simple to parse it for what you are looking for and show your own rain images.

    Celebrate Intellectual Diversity

Re: Weather RSS image
by valdez (Monsignor) on Nov 09, 2005 at 21:32 UTC

    Welcome at the Monastery!
    There is a better way to do this: instead of grabbing that page, build your own page using data got via RSS! Grab the data available from one of the sources listed at Yahoo RSS using XML::RSS::Feed and build the page you want with HTML::Template. Have fun!

    Ciao, Valerio

Re: Weather RSS image
by pg (Canon) on Nov 09, 2005 at 21:46 UTC

    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.

      (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).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://507207]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2017-07-23 20:07 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (347 votes). Check out past polls.