in reply to HTML::Parser fun
Just to show you how darn easy, accurate, deep, and fast some of this is with XML::LibXML...
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; # This is a shortcut, see the docs for more formal usage. my $doc = XML::LibXML->new->parse_html_fh(*DATA); my $root = $doc->getDocumentElement; my ( $head ) = $root->findnodes("head"); my ( $body ) = $root->findnodes("body"); print "Head stuff...\n"; for my $refresh ( $head->findnodes('meta[@http-equiv]') ) { print "\t", $refresh->getAttribute("content"), "\n"; } print "\nBody stuff...\n"; for my $link ( $body->findnodes('a[@href]') ) { printf("%25s --> %s\n", $link->textContent || $link->getAttribute("title") || "n/a" +, $link->getAttribute("href") ); } # print $doc->serialize(1); __DATA__ PUT YOUR HTML DOCUMENT DOWN HERE. Took it out for space.
Reproducing the same output/report format you want is left as an excercise for the reader. :) The docs for the family of modules are terse but quite good once you see the big picture. There are options to allow more liberal/broken HTML to be parsed (or attempted anyway).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HTML::Parser fun
by FreakyGreenLeaky (Sexton) on Jun 05, 2008 at 14:54 UTC | |
by Your Mother (Archbishop) on Jun 05, 2008 at 16:15 UTC | |
by FreakyGreenLeaky (Sexton) on Jun 06, 2008 at 17:48 UTC | |
by Your Mother (Archbishop) on Jun 06, 2008 at 18:44 UTC | |
by mirod (Canon) on Jun 05, 2008 at 15:05 UTC | |
by FreakyGreenLeaky (Sexton) on Jun 05, 2008 at 15:11 UTC | |
|
Re^2: HTML::Parser fun
by FreakyGreenLeaky (Sexton) on Jun 05, 2008 at 09:35 UTC |