Monks, I'm in dire need of some direction. I'm trying to read some html tables and ingest them into an Sql DB using perl. I cant for the life of me understand regex and matching tags So let me give see if i can explain this better. A sample of the table looks like this (machine generated)
<BR><B> 00:00 - 00:15 </B> <TABLE BORDER> <TR> <TD> Channel </TD> <TD> Call Letters </TD> <TD> Count </TD> <TD> Percent </TD> <TD> Title </TD> </TR> <TR></TR> <TR> <TD align=right> 1 </TD> <TD > &nbsp; ch1 &nbsp; </TD> <TD align=right> 22 </TD> <TD > &nbsp; 6.52% &nbsp; </TD> <TD > Program 1 </TD> </TR> <TR> <TD align=right> 3 </TD> <TD > &nbsp; Ch1 &nbsp; </TD> <TD align=right> 5 </TD> <TD > &nbsp; 1.48% &nbsp; </TD> <TD > Program2 </TD> </TR> <TR> <TD align=right> 4 </TD> <TD > &nbsp; Ch 3 &nbsp; </TD> <TD align=right> 1 </TD> <TD > &nbsp; 0.29% &nbsp; </TD> <TD > Program3 </TD> </TR> <TR> <TD align=right> 5 </TD> <TD > &nbsp; CH53 &nbsp; </TD> <TD align=right> 5 </TD> <TD > &nbsp; 1.48% &nbsp; </TD> <TD > Program4 </TD> </TR> <TR> <TD align=right> 6 </TD> <TD > &nbsp; C &nbsp; </TD> <TD align=right> 3 </TD> <TD > &nbsp; 0.89% &nbsp; </TD> <TD > Program5 </TD> </TR> </TABLE>
It pretty much loops like this throughout, what i'm trying to do is convert this to a csv or something and ingest it into a DB. If i can directly write to the DB when looping through that'll be ever better. Let me know if you can help me. With any solution. P.S this is my script so far.
use warnings; use strict; use HTML::TableExtract; use LWP::Simple; my $file ="/path/to/file/file.htm"; my $T = HTML::TableExtract->new(); my $table = $T->parse_file($file) ->first_table_found; my @rows = $table->rows; foreach my $row ($T->rows) { print join(',', @$row), "\n"; }
It only processes the FIRST table tho... not the rest of the document.

In reply to HTML Table to MYSQL DB by Fiddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.