Just by way of closing this post, and giving back a bit so that others in my position can search for it (and find the answer without bothering the murmuring monks):
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'uninitialized';
use HTML::TokeParser::Simple;
my $p = HTML::TokeParser::Simple->new($ARGV[0]);
my $tag = '';
while (my $tkn = $p->get_token)
{
if ($tkn->is_start_tag('title')) { $tag = "TITLE"; }
elsif ($tkn->is_start_tag('h1')) { $tag = "H1"; }
elsif ($tkn->is_start_tag('h2')) { $tag = "H2"; }
elsif ($tkn->is_start_tag('h3')) { $tag = "H3"; }
elsif ($tkn->is_start_tag('h4')) { $tag = "H4"; }
elsif ($tkn->is_start_tag('h5')) { $tag = "H5"; }
elsif ($tkn->is_start_tag('h6')) { $tag = "H6"; }
elsif ($tkn->is_start_tag('b')) { $tag = "B"; }
elsif ($tkn->is_start_tag('i')) { $tag = "I"; }
elsif ($tkn->is_start_tag('u')) { $tag = "U"; }
elsif ($tkn->is_start_tag('a')) { $tag = "A"; }
elsif ($tkn->is_start_tag('img')) { $tag = "IMG"; }
elsif ($tkn->is_start_tag('meta')) { $tag = "META"; }
elsif (
$tkn->is_end_tag('title') ||
$tkn->is_end_tag('h1') ||
$tkn->is_end_tag('h2') ||
$tkn->is_end_tag('h3') ||
$tkn->is_end_tag('h4') ||
$tkn->is_end_tag('h5') ||
$tkn->is_end_tag('h6') ||
$tkn->is_end_tag('b') ||
$tkn->is_end_tag('i') ||
$tkn->is_end_tag('u') ||
$tkn->is_end_tag('a') ||
$tkn->is_end_tag('img') ||
$tkn->is_end_tag('meta')
) { $tag = ''; }
elsif ($tkn->is_text() && $tag && $tag ne 'META')
{
print "TAG: $tag, VALUE: ".$tkn->as_is . "\n";
}
if ($tag eq 'IMG' && $tkn->get_attr('alt'))
{
print "TAG: $tag, ALT VALUE: ". $tkn->get_attr('alt') . "\n";
}
if ($tag eq 'META' &&
$tkn->get_attr('name') eq 'keywords' &&
$tkn->get_attr('content'))
{
print "META-TAG: $tag, KEYWORDS VALUE: ". $tkn->get_attr('cont
+ent') . "\n";
}
if ($tag eq 'META' &&
$tkn->get_attr('name') eq 'description' &&
$tkn->get_attr('content'))
{
print "META-TAG: $tag, DESCRIPTION VALUE: ". $tkn->get_attr('c
+ontent') . "\n";
}
}
-
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.
|