TokeParser problems - grab http-equiv ???

This works fine! It always grabs the $name and $content of the
Meta tags just like it's supposed too!
example:  
$name = "Author";
$content = "John Doe";

 $parser=HTML::TokeParser->new(\$webPage);
          while (my $token=$parser->get_tag("meta"))
           {
            $name=$token->[1]{name};          # grabs name here
            $content=$token->[1]{content};     # grabs content here
            $HashMeta{$name}=$content;        
           }


The following doesn't work! How do I grab the HTTP-EQUIV name ?
It always returns blank "" for $name.  I've tried using capitals, etc...

 $parser=HTML::TokeParser->new(\$webPage);
          while (my $token=$parser->get_tag("meta"))
           {
            $name=$token->[1]{http-equiv};     # cant grab this
            $content=$token->[1]{content};       # grabs content here
            $HashMeta{$name}=$content;  
           }

Example:
$name=""
$content="what it should be";

Also, how would I make it grab ANY tags within Meta?  There are some real weird ones (like dublin core).  Anyone got any code for this?  P.S.  You don't have to answer this last part!
jgoreAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
clockwatcherConnect With a Mentor Commented:
The '-' sign is throwing you off.  Try this and I think you'll have better luck:

 $name=$token->[1]{'http-equiv'};

To list all the tags within a meta simply iterate through the keys:

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

$page = qq(
<html>
<head>
<meta http-equiv="refresh" content="1,http://www.somewhere.com">
<meta name="author" content="me">
<meta name="keyword" content="perl,tokeparser">
<meta HTTP-EQUIV="content-type" content="text/html">
<meta whatever="something" what-about-this="sure">
</head>
<body>
Hello
</body>
</html>
);

$parser = HTML::TokeParser->new(\$page);

while (my $token=$parser->get_tag("meta"))
  {
    foreach (sort keys %{$token->[1]}) {
      print "$_ : $token->[1]{$_}\n";
    }
    print "\n\n";
  }



 

0
 
jgoreAuthor Commented:
Thanks ClockWatcher!
0
All Courses

From novice to tech pro — start learning today.