Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello. I'm writing a program that records the names of 25000+ users who place pretend bets at a fantasy sports website. I have already written a program that successful extracted all of their names. I then saved this to a file.

Then, to access each player's record, my program begins by setting up an array with an entry for each of the players. By typing in www.blablabla.combla?(PLAYERSNAME) I can get more detailed information about that player. Depending on what sports the player has placed bets on (there are 11 including a record for ALL sports), there will be a link if he has placed bets on those sports. I initially skim the general page to find out what sports he played, then I create an array that captures each sport. THen I proceed to get detailed records for each sport by creating an array of the sports he has played.

My program then loops through the @sports array that contains the sports they've played. Unfortunately, sometimes my program simply does not extract values for a whole loop of the array. I think my regexps are okay, because I can ALWAYS rerun the program from the failed point and successfully and accurately capture values for that iteration. Below is the code (any other recommendations as to better programming design are welcome

$browser = LWP::UserAgent->new(); $browser->agent("Mozilla/4.76 [en] (Win98; U)"); @sports= qw(ALL); open PLAYERS, "players.txt" or die; sub urldefine { + $url= URI-> new(''); + $url->query_form( 'Member' => $_[0], 'Sport' => "$_[1]",); } while (<PLAYERS>) { chomp $_; push (@plyrs, $_); } open DUMP, ">dump.txt" or die; open STATS2, ">>stats2.txt" or die; for ($i=17022; $i <= 19000; $i+=1) { @sports=(); @urlfeed = ($plyrs[$i], "all"); urldefine @urlfeed; $page=get("$url"); for my $a (split "&Spo", $page) { if ($a =~ /rt=(\w*)"/g) { push (@sports, $1); } } for ($j=0; $j <= $#sports; $j+=1) { print "."; @urlfeed = ($plyrs[$i], $sports[$j]); urldefine @urlfeed; $page= get("$url"); print STATS2 "Player\t", "Sport\t", "Season\t", "BetType\t +"; print STATS2 "Record\t", "Wins\t", "Losses\t", "Ties\t", " +Percent\t"; print STATS2 "Units\t", "Rank\t", "TotalRank\n"; for my $a (split "/td>", $page) { if ($a =~ /al">([AC]\w{2})/m) { $year="$1"} if ($a =~ /al">(\d{4})/m) { $year="$1"} if ($a =~ /"2">([AO].*?)</m) { print STATS2 $plyrs[$i], "\t", $sports[$j], "\ +t", $year. "\t", $1. "\t"; } if ($a =~ /18%"><SMALL>([^<].*?)</m) { print STATS2 $1, "\t"; if ($1 =~ /(\d+)-(\d+)-(\d+)/m) {print STATS2 +$1, "\t", $2, "\t", $3, "\t"} if ($1 eq "N/A") {print STATS2 $1, "\n"} } elsif ($a =~ /18%"><SMALL>.*?>(\d*)\s\w{2}\s(\ +d*)/m){ print STATS2 $1, "\t", $2, "\n"; } } } print "Finished Player #", $i+1,": ", $plyrs[$i], "\n"; }

20040824 Janitored by Corion: Added code tags

In reply to question about LWP and mysterious skipping over of pages by dchandler

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?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (9)
    As of 2020-10-28 14:16 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (261 votes). Check out past polls.