Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://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('http://www.wagerline.com/showprofile.asp?'); + $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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found