liverpaul has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I've been teaching myself HTML::Parser. So far I'm able to process each tag and each text, but I'm having trouble figuring out how to access the attribute.
Here's what I'm testing:
At the moment I can process a html file and output just the tags that I want. However, within that group I want to filter again by attribute. I've searched for solutions, but they either don't match my example, or are too difficult for me to follow. Can anyone help me please?use HTML::Parser(); # Create instance $p = HTML::Parser->new(start_h => [\&start_rtn, 'tag'], text_h => [\&text_rtn, 'text'], end_h => [\&end_rtn, 'tag']); # Start parsing $p->parse_file('http://www.mysite.com'); sub start_rtn { # Execute when start tag is encountered foreach (@_) { print "Start tag = $_\n"; } } sub text_rtn { # Execute when text is encountered foreach (@_) { print "Text = $_\n"; } } sub end_rtn { # Execute when the end tag is encountered foreach (@_) { print "End = $_\n"; } }
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl::Parser access attributes
by Anonymous Monk on Sep 07, 2012 at 03:27 UTC | |
by liverpaul (Acolyte) on Sep 07, 2012 at 06:38 UTC |