in reply to Parse... then what? (HTML Parsing problems)
I think that for many HTML tasks HTML::TokeParser is a good module, it is a slightly simpler interface to HTML::Parser. When you parse with HTML::Parser you have to have all of your handlers and logic set up before you can call parse(). But HTML::TokeParser will turn the entire HTML document into a stack of tokens that you can shift and unshift as needed. The tokens correspond to each element of your HTML page.
Because your program's logic is based on just a few criteria happening in an order, this is the perfect time for that. Here is some pseudocode that would use HTML::TokeParser:
#Get HTML Document #HTML::TokeParser->new( HTML ) #get first Token #until ( TokenTag eq 'h3' and TokenText eq 'foo') # get next Token #if EndOfHTML then exit #until ( TokenTag eq 'em' ) # get next Token #declare EM container #until ( get TokenTag eq 'hr' ) # add TokenText to EM container # get next Token #use EM container
As you can see, this logic is a lot simpler than trying to set up handlers for each of the tags you care about, then trying to manage states-- which is about what you have to do with HTML::Parser.
|
|---|