I have been trying to figure out the best way to parse some chunks of html code that contain tables. I've been trying to do this with HTML::Parser and HTML::TokeParser and HTML::TokeParser::Simple, but I just can't seem to get everything working the way I want. The chunks are from a standard template so there is some structure to the data, but it is not that simple.
The problem:
There can be bare text before, after or between each table in the chunk.
There can be embedded tables (tables within tables)
There can be multiple tables in series. (one after the other)
There can be embedded tables and tables in series in the same chunk.
If you've ever looked at a PHPBB forum, the chunks I am working with are the posts. The tables are quoted text within those posts. I need to remove the HTML code and replace it with the BBCode used by the forum so it can then be put into the database. I know PHPBB uses a database backend, but I do not and cannot get access to it.
What I am trying to accomplish is to pull the text out of the table and then eventually insert it into the database. Where I'm having problems is storing the text in a variable so that it can be recreated in the order in which it would look on the html page in a browser.
With HTML::Parser I was able to get a single table of data out, but when I started getting into the multiple levels of tables, I didn't really have a clean way to hold on to what I had already parsed while I continued through the chunk.
With HTML::TokeParser::Simple I was able to do the same thing, but I end up in a sea of flags trying to capture the right data at the right time. If I had a way with this module to extract the contents of the entire table structure and then parse that one thing at a time, I think I'd be all set. I seem to be able get close to the solution with both modules coming at the problem from two different directions, but can't quite get the entire solution.
Can anyone provide any insight into what I might possibly try or consider in order to get this project finished? I'm not asking for help with the coding per se, just a useful design method to solve this problem. I'm not a perl expert by any means, but I can make my way through the docs and some books to figure most things out.