Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This example uses HTML::TokeParser to locate all of the META tags in a document.

#!/usr/bin/perl -w use strict; use HTML::TokeParser; # get the file name to parse from the command line my $html = shift or die 'Specify a file name'; # access the file with the parser my $p = HTML::TokeParser->new($html) or die $!; # loop through all tokens while (my $r = $p->get_token) { # $r->[0] tells us if it's a Start tag, End tag, Text, Comment # for start tags, $r->[1] tells us the type of tag # only process META start tags next unless $r->[0] eq 'S' && $r->[1] eq 'meta'; print "Found <meta> tag\n"; # $r->[2] is a hash ref containing attributes and values while (my ($k,$v) = each %{$r->[2]}) { print "\t$k = $v\n"; } }

Here's the result from running it against an html file on my system.

$ perl meta.pl ~/public_html/cvsbook.html Found <meta> tag content = text/html http-equiv = Content-Type Found <meta> tag content = Open Source Development With CVS name = description Found <meta> tag content = makeinfo 4.0 name = generator
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

In reply to Re: I need more docs by pfaut
in thread Seeking HTML parsing examples by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2020-10-20 00:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (208 votes). Check out past polls.

      Notices?