Brian Volk <[EMAIL PROTECTED]> wrote:

: Hi All,
:
: I'm trying to only get the text from w/in a certain table in
: the HTML source.   Right now I am getting all the text in the
: source.
: Here is my script.... I made notes in the script.
:
:  #!/usr/bin/perl -w

    Always use strict.

use strict;

:  use HTML::TokeParser::Simple;

[snip]
: my $parser = HTML::TokeParser->new(\$page) ||
:                           die "Could not parse page";

    Wrong object.

my $parser = HTML::TokeParser::Simple->new( \$page ) ||
                            die "Could not parse page";


[snip]
: # ---------- with this I get Use of uninitialized value in
: # print..  I think LWP::Simple is returning that? ---------

    No, both $attr and $tag are undefined.

: # my $tag = $parser->get_tag("table") foreach (1..28);
: # my $attr = $tag->[1]->{"colspan"};
: # print $tag->[0], ":",  $attr, "\n";

    You are attempting to access the 28th table, but there are
only 27 tables in the document.

use strict;
use warnings;

use HTML::TokeParser::Simple;
use LWP::Simple;

my $url  = 'http://www.kcprofessional.com/us/product-details.asp'
           . '?search=v1&searchtext=01970&x=0&y=0';

my $page = get( $url ) || die qq(Could not load "$url");

my $parser = HTML::TokeParser::Simple->new( \$page ) ||
                            die "Could not parse $url";

my $table_count;

++$table_count while $parser->get_tag( 'table' );

print "$table_count tables found.\n";


[snip]
: # ---------- I have get_attr # out because I get can't locate
: # in @INC -- (using ActiveState Perl)

    There is no get_attr() method in HTML::TokeParser::Simple. We
can verify this using the can() method.

use strict;
use warnings;
use HTML::TokeParser::Simple;

my $parser = HTML::TokeParser::Simple->new(*DATA) ||
                                die "Could not parse page";

printf
    "The get_attr() method %s\n",
    $parser->can( 'get_attr' ) ? 'exists' : 'does not exist';

__END__


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to