Thanks to ase (who I can't put in brackets, I get a server error), I've been playing with the
HTML::TableExtract module. This is a really slick little module for extracting table data from HTML pages. However, it has a minor drawback for what I'm trying to do. If there is any HTML data between the <TD> and </TD> tags, it gets stripped. I would like it to return the HTML between the tags, and I've figured out how to do that. Unfortunately, I can't figure out how to access the data I've stored. Below is a model of what's happening:
- HTML::TableExtract is a sub-class of HTML::Parser.
- jcwExtract is a sub-class of HTML::TableExtract.
- jcwExtract overrides the start() method of HTML::TableExtract, and successfully pulls the data I want, storing it in a private hash (the classic $self->{sometag} = thatdata)
- HTML::Extract has an internal package called HTML::TableExtract::TableState.
- HTML::TableExtract::TableState has a method called _add_text(), that adds the text found in the table to a 'TableState object'
I need to override the _add_text() method in the HTML::TableExtract::TableState class, which I can do with 'sub HTML::TableExtract::TableState::_add_text'. This is dirty, but works (with a warning). I'd rather subclass the HTML::TableExtract::TableState package, and invoke the parent _add_text() routine with a $self->SUPER::_add_text() call. However, since the HTML::TableExtract::TableState package is internal to the HTML::TableExtract module, and HTML::TableExtract explicitly does a '$ts = new HTML::TableExtract::TableState()', I don't know how to accomplish the goal.
The _add_text() that I provide needs to access the data I've stored in the jcwExtract module. If I can either figure out how to access the parent's parent data (HTML::TableExtract::TableState -> HTML::TableExtract -> ->jcwExtract), I can do this, but it feels unclean. I'd rather figure out how to subclass the HTML::TableExtract::TableState module and override the _add_text() method.
I would post the code, but it's a little lengthy, so instead, here's a
link to it. It's difficult to boil down to a short test case, but I'll try to add some more to it in a bit. I'll be happy to try any suggestions anyone has as to how to pull this off...
--Chris
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.