Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
merlyn,
This certainly isn't as succinct but I wanted to offer my contribution. It gets 110 of the 118 non-exclusive pics. All 8 of Marisa Miller's are skipped. It was fun - *shrug*.
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTML::TableContentParser; use HTML::TokeParser::Simple; use Data::Dumper; use constant MODELS => 3; use constant PICS => 4; -d "RESULTS" or mkdir "RESULTS", 0755 or die "cannot mkdir RESULTS: $! +"; chdir 'RESULTS' or die "cannot chdir RESULTS: $!"; my $url = 'http://sportsillustrated.cnn.com/'; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get( $url . 'features/2005_swimsuit/' ); my $table = HTML::TableContentParser->new()->parse( $mech->content() ) +; for my $row ( @{ $table->[MODELS]{rows} } ) { for my $cell ( @{ $row->{cells} } ) { my $link = get_link( $cell ); if ( $link ) { $mech->get( $url . $link ); my $t = HTML::TableContentParser->new()->parse( $mech->con +tent() ); for my $r ( @{ $t->[PICS]{rows} } ) { for my $c ( @{ $r->{cells} } ) { my $p = get_pic( $c ); if ( $p ) { my ($file) = $p =~ m|/([^/]+)$|; print "Checking $file\n"; if (-e $file) { print "skipping $file - already have\n"; } else { print "Downloading $file\n"; # Add error handling with $response if you + want my $response = $mech->mirror($p, $file); select(undef, undef, undef, .05); } } else { next; } } } } else { print STDERR "No link found in ", $cell->{data}, "\n"; } } } sub get_link { my $link = shift; my $p = HTML::TokeParser::Simple->new( \$link->{data} ); my $token = $p->get_token; return $token->is_start_tag( 'a' ) ? $token->return_attr( 'href' ) + : undef; } sub get_pic { my $link = shift; my $p = HTML::TokeParser::Simple->new( \$link->{data} ); while ( my $token = $p->get_token ) { next if ! $token->is_start_tag( 'img' ); my $src = $token->return_attr( 'src' ); if ( $src =~ m|/05_[\w]+_0\dt\.jpg$|i ) { $src =~ s/t\.jpg$/.jpg/i; return $src; } else { return undef; } } return undef; }
I didn't bother fixing it to get the exclusive photos, but it shouldn't be too difficult. Incidently, there is a non-linked photo we both miss. Carolyn Murphy has a hidden #2 pic.

Cheers - L~R


In reply to Re: Swimsuits2005 by Limbic~Region
in thread 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2017-12-11 05:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (286 votes). Check out past polls.

      Notices?