in reply to Parsing COD text help

I would suggest you use the html source and use HTML::TokeParser to parse it out. The following might be a good place to start. (I saved the html source into the file "APMA.txt")

#!/usr/bin/perl use HTML::TokeParser; use strict vars; my $file = 'APMA.txt'; my $stream = HTML::TokeParser->new($file); my $tok; while( $tok = $stream->get_token) { if( $tok->[1] eq 'a' && $tok->[2]{'href'} =~ m/course_nbr/ ) { print "Class: " . $stream->get_text('/a') . " "; } if( $tok->[1] eq 'span' && exists($tok->[2]{'class'}) && $tok->[2] +{'class'} eq "title") { print $stream->get_text('/span') . "\n"; } if( $tok->[1] eq 'span' && exists($tok->[2]{'title'}) && !exists($ +tok->[2]{'class'}) ) { print "Title = $tok->[2]{'title'}: "; print $stream->get_text('/span'), "\n"; } } exit;
partial output:

Class: APMA 109 Calculus I Title = Schedule Number: 92861 Title = Section Number: 0001 Title = Credit Hours: 04.0 Title = Time: 0900-0950 Title = Day:MTWRFS: MWF Title = Olsson Hall: OLS 011 Title = Instructor: Oberhauser, James P. Title = Enrollment:Authorized/Actual: 55/2 Title = Grading Method: O Title = Time: 0830-0920 Title = Day:MTWRFS: T Title = Olsson Hall: OLS 005 Title = Instructor: Title = Schedule Number: 90063 Title = Section Number: 0002 Title = Credit Hours: 04.0 Title = Time: 1000-1050 Title = Day:MTWRFS: MWF Title = Olsson Hall: OLS 120 Title = Instructor: Beck, Mary Title = Enrollment:Authorized/Actual: 55/4 Title = Grading Method: O Title = Time: 0830-0920 Title = Day:MTWRFS: R Title = Olsson Hall: OLS 120 Title = Instructor: ... Class: APMA 111 Single Variable Calculus Title = Schedule Number: 93433 Title = Section Number: 0001 Title = Credit Hours: 04.0 Title = Time: 1100-1150 Title = Day:MTWRFS: MWF Title = Olsson Hall: OLS 011 Title = Instructor: Title = Enrollment:Authorized/Actual: 55/55 Title = Grading Method: O Title = Time: 0830-0920 Title = Day:MTWRFS: T Title = Instructor: Castiglione, Jason ...
Further parsing is easily done to get exactly what you want.
Take a look at Perl & LWP for more information.

Hope this helps,
davidj

Replies are listed 'Best First'.
Re^2: Parsing COD text help
by Aristotle (Chancellor) on Jul 26, 2004 at 02:57 UTC
    Of course, you should never say HTML::TokeParser without the ::Simple. :)
    #!/usr/bin/perl use strict; use warnings; use HTML::TokeParser::Simple; my $file = 'APMA.txt'; my $stream = HTML::TokeParser::Simple->new( $file ); while( my $t = $stream->get_token ) { if( $t->is_start_tag( 'a' ) and $t->return_attr( 'href' ) =~ m/course_nbr/ ) { print "Class: ", $stream->get_text( '/a' ), " "; } elsif( $t->is_start_tag( 'span' ) ) { my $class = $t->return_attr( 'class' ); my $title = $t->return_attr( 'title' ); if( defined $title and not defined $class ) { print "Title = $title: ", $stream->get_text( '/span' ), "\ +n", } elsif( defined $class and $class eq 'title' ) { print $stream->get_text( '/span' ), "\n"; } } }

    Makeshifts last the longest.