in reply to html to hash table
I don't know how well it works, but HTML::Parser (H::P) has options to call your "callout function" for the opening and closing tags of specific HTML elements, or all of them. When you specify the callout functions, you tell H::P what you want passed to your function. For example I wanted to see the start/stop/text and non-parsed text (DATA/javascript) so I specified functions for each (mayka is a anon-sub creation routine that included some routine error checks and such).
The last parameter specified what elements I wanted passed to my function, so for tags that had class labels, I could store & nest them.$p->parser(HTML::Parser->new("api_version" => 3, start_h => [ mayka($p,6,start_h => \&_start), "tag,skipped_text,attr,attrseq,line,text"], end_h => [ mayka($p,4,end_h => \&_end), "tagname,skipped_text,line,offset_end"], text_h => [ mayka($p,3, text_h => \&_text), "tag,skipped_text,text"], default_h => [ mayka($p,3,default_h => \&_dflt), "event, skipped_text, text"], marked_sections => 1,));
Note -- I may easily be missing some functionality in WWW::Mechanize, but I didn't see the ability to process class or ID values when they started and ended. It does get a bit hairy trying to keep track of them, since nested elements preempt and assign class+id's to children, and when those elements end, the class+id revert to whatever was in place before you encountered that element (i.e. need to maintain a stack)...
hope this helps...
|
|---|