Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi I posted yesterday about HTML parsing, and I've been trying to figure out how to use the HTML::TokeParser. I was pointed to the tutorial yesterday but am a little stuck. Maybe someone can help me get a start. Basically I'm trying to go through all the INPUT+TEXTAREA tags in my local HTML file and take the name of the field which is in the tag and looks like name=var1 or name="var1". Thank you very much.
  • Comment on Help using HTML::TokeParser to find INPUT and TEXT area tags

Replies are listed 'Best First'.
Re: HTML::TokeParser
by Ovid (Cardinal) on Aug 29, 2002 at 16:55 UTC

    I'd use HTML::TokeParser::Simple. It's much easier to use and has several code samples included in the POD.

    use HTML::TokeParser::Simple; my $p = HTML::TokeParser::Simple->new( $somefile ); while ( my $token = $p->get_token ) { next unless $token->is_start_tag( 'input' ) or $token->is_start_t +ag( 'textarea' ); my %attribute_hash = %{ $token->return_attr }; # do your thing ... }

    In the snippet above, %attribute_hash contains the attribute names and values. It's up to you to figure out what you want to do with them.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: HTML::TokeParser
by Anonymous Monk on Aug 29, 2002 at 17:15 UTC
    Thanks for the reply but I'm finding that HTML::TokeParser::Simple is not supported on my server. It's not built in to my perl dir.

      The typical solution to this problem would be to install the module. . .see this node for a VERY nice tutorial by tachyon.

      -Any sufficiently advanced technology is
      indistinguishable from doubletalk.