Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Who has used HTML::Parser??

by nardo (Friar)
on Jul 06, 2000 at 04:56 UTC ( #21262=note: print w/replies, xml ) Need Help??


in reply to Who has used HTML::Parser??

The "main parser function" is either parse() or parse_file() depending on whether you have the html in memory or on disk. The parser has three functions: start, end, and text, which will be called when a new tag is encountered, ended, and text is found. You need to supply these functions yourself. Version 2 of HTML::Parser requires you to subclass HTML::Parser:
#!/usr/bin/perl use strict; { package SampleParser; use base qw(HTML::Parser); sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; my $at; print "Tag: $tagname\n"; foreach $at (@{$attrseq}) { print "Attribute: $at = $attr->{$at}\n"; } } sub text { my ($self, $origtext) = @_; print "Text: $origtext\n"; } } my $html = '<html><head><title>this is the title</title><body bgcolor= +"white">Hello</body></html>'; my $sp = new SampleParser; $sp->parse($html)
But version 3 looks like it allows you to specify which functions to use for start end and text in the constructor (see the documentation for an example of this).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://21262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2019-06-25 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (101 votes). Check out past polls.

    Notices?