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

comment on

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

O wise monks:

Noob (me) wants to extract a sports schedule from a website. Here's my code:

#!/usr/bin/perl -w use strict; use LWP::Simple; use HTML::TokeParser; my $url = 'http://www.georgiastatesports.com/SportSelect.dbml?DB_OEM_I +D=12700&SPID=5671&SPSID=53628'; my $raw = get($url); my $stream = HTML::TokeParser->new(\$raw) or die "$url $!"; while(my $token = $stream->get_token() ) { my $ttype = shift @{ $token }; if ($ttype eq "S") { my($tag, $attr, $attrseq, $rawtxt) = @{ $token }; next until ($tag eq "table"); my $class = $attr->{'class'}; if ($class eq "ScheduleTable") { my $sched = $stream->get_trimmed_text("/$tag"); print "$sched\n"; } # class eq "ScheduleTable" } # $ttype eq "S" } # while

What I hoped to return:

Date Opponent Location Time (ET) Results Overall CAA Media Thu, Aug 30 South Carolina State Georgia Dome 7:30 PM Sat, Sep 08 Tennessee at Knoxville, Tenn. 4:00 PM PPV Sat, Sep 15 UTSA Georgia Dome 6:00 PM Sat, Sep 22 Richmond * Georgia Dome 3:30 PM Sat, Sep 29 William & Mary * at Williamsburg, Va. 7:00 PM CSS-TV Sat, Oct 06 New Hampshire * Georgia Dome 3:30 PM Sat, Oct 13 Rhode Island * at Kingston, R.I. 1:00 PM Sat, Oct 20 Villanova (Homecoming) * Georgia Dome 3:30 PM Sat, Oct 27 James Madison * at Harrisonburg, Va. 3:30 PM Sat, Nov 03 Old Dominion * Georgia Dome 3:30 PM Sat, Nov 10 Maine * at Orono, Maine 2:00 PM

What I got:

Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Date Opponent Location Time (ET) Results Overall CAA Media ? Thu, Aug +30 ?South Carolina State Georgia Dome ? 7:30 PM ? Sat, Sep 08 ?Tennes +see at Knoxville, Tenn. ? 4:00 PM PPV ? Sat, Sep 15 ?UTSA Georgia Dom +e ? 6:00 PM ? Sat, Sep 22 ?Richmond * Georgia Dome ? 3:30 PM ? Sat, S +ep 29 ?William & Mary * at Williamsburg, Va. ? 7:00 PM CSS-TV ? Sat, +Oct 06 ?New Hampshire * Georgia Dome ? 3:30 PM ? Sat, Oct 13 ?Rhode I +sland * at Kingston, R.I. ? 1:00 PM ? Sat, Oct 20 ?Villanova (Homecom +ing) * Georgia Dome ? 3:30 PM ? Sat, Oct 27 ?James Madison * at Harri +sonburg, Va. ? 3:30 PM ? Sat, Nov 03 ?Old Dominion * Georgia Dome ? 3 +:30 PM ? Sat, Nov 10 ?Maine * at Orono, Maine ? 2:00 PM Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18. Use of uninitialized value $class in string eq at ./gsu2.pl line 18.

A hexdump where the newlines should be shows a character sequence of \0x20\0xA0\0x20. I tried

local $/ = \0xA0;

between get_trimmed_text() and print, without any apparent effect.

How would I get newlines before each date and handle the "uninitialized" warnings? I await your wisdom.


In reply to TokeParser and newlines by SilverSpring8

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? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-12-08 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?