Well, it's that cold and dark time of the year again, time for the Sports-Illustrated-Swimsuits auto-download. This is a pretty fair sampling. Any code improvements welcome. This could be done easier with LWP::Simple, but I wanted to show some download progress(since each picture is =~ 400k, and throw in a little user-agent fakeout :-))

UPDATE 1-21-05 Miscellaneous fixes for binmode and server load.

#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; my $a = int rand(9); my $a1 = int rand(9); my $agent = "Mozilla/1.$a.$a1 (compatible; MSIE; NT 6.0 )"; my $ua = LWP::UserAgent->new( env_proxy => 0, timeout => 50, keep_alive => 1, agent => $agent, ); my @pics = qw( 04_mandersen_01.jpg 04_mandersen_02.jpg 04_mandersen_03.jpg 04_mandersen_04.jpg 04_mandersen_05.jpg 04_mandersen_06.jpg 04_mandersen_07.jpg 04_alindvall_01.jpg 04_alindvall_02.jpg 04_alindvall_03.jpg 04_alindvall_04.jpg 04_akournikova_01.jpg 04_akournikova_02.jpg 04_akournikova_03.jpg 04_akournikova_04.jpg 04_bhall_01.jpg 04_bhall_02.jpg 04_bhall_03.jpg 04_bhall_04.jpg 04_bhall_05.jpg 04_bhall_06.jpg 04_cmurphy_01.jpg 04_cmurphy_02.jpg 04_cmurphy_03.jpg 04_cmurphy_04.jpg 04_dpestova_01.jpg 50th_dpestova_01.jpg 04_ebenitez_01.jpg 04_ebenitez_02.jpg 04_ebenitez_03.jpg 04_ebenitez_04.jpg 04_ebenitez_05.jpg 04_fmotta_01.jpg 04_fmotta_02.jpg 04_fmotta_03.jpg 04_fmotta_04.jpg 04_frayder_01.jpg 04_frayder_02.jpg 04_frayder_03.jpg 04_frayder_04.jpg 04_jvandersteen_01.jpg 04_jvandersteen_02.jpg 04_jvandersteen_03.jpg 04_jvandersteen_04.jpg 04_jwhite_01.jpg 04_jwhite_02.jpg 04_jwhite_03.jpg 04_jwhite_04.jpg 04_jwhite_05.jpg 04_jwhite_06.jpg 04_jwhite_07.jpg 04_mmiller_01.jpg 04_mmiller_02.jpg 04_mmiller_03.jpg 04_mmiller_04.jpg 04_mmiller_05.jpg 04_mmiller_01.jpg 50th_mmiller_01.jpg 04_mkeller_01.jpg 04_mkeller_02.jpg 04_mkeller_03.jpg 04_mkeller_04.jpg 04_mkeller_05.jpg 04_mkeller_06.jpg 04_msims_01.jpg 04_msims_02.jpg 04_msims_03.jpg 04_msims_04.jpg 04_pnemcova_01.jpg 04_pnemcova_02.jpg 04_pnemcova_03.jpg 04_pnemcova_04.jpg 04_pnemcova_05.jpg 04_pnemcova_06.jpg 04_vvarekova_01.jpg 04_vvarekova_02.jpg 04_vvarekova_03.jpg 04_vvarekova_04.jpg 01_vvarekova_01.jpg 00_vvarekova_01.jpg 99_vvarekova_01.jpg ); foreach my $pic(@pics){ my $URL = "http://i.cnn.net/si/pr/subs/swimsuit/images/$pic"; my $filename = $pic; my $expected_length; my $bytes_received = 0; my $result = $ua->head($URL); if ($result->is_success) { open( IN, ">$filename" ) or warn $!; binmode(IN); my $response = $ua->request(HTTP::Request->new(GET => $URL), sub { my ( $chunk, $res ) = @_; $bytes_received += length($chunk); unless ( defined $expected_length ) { $expected_length = $res->content_length || 0; } if ($expected_length) { printf STDERR "%d%% - ", 100 * $bytes_received / $expect +ed_length; } print STDERR "$bytes_received bytes received $pic\r"; print IN $chunk; } ); print $response->status_line, "\n"; }else{print "$pic ",$result->status_line,"\n"} close IN; sleep(1 + rand(5)); } exit;

In reply to Swimsuits2004 by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.