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 >
ch1 </TD>
<TD align=right>
22 </TD>
<TD >
6.52% </TD>
<TD >
Program 1 </TD>
</TR>
<TR>
<TD align=right>
3 </TD>
<TD >
Ch1 </TD>
<TD align=right>
5 </TD>
<TD >
1.48% </TD>
<TD >
Program2 </TD>
</TR>
<TR>
<TD align=right>
4 </TD>
<TD >
Ch 3 </TD>
<TD align=right>
1 </TD>
<TD >
0.29% </TD>
<TD >
Program3 </TD>
</TR>
<TR>
<TD align=right>
5 </TD>
<TD >
CH53 </TD>
<TD align=right>
5 </TD>
<TD >
1.48% </TD>
<TD >
Program4 </TD>
</TR>
<TR>
<TD align=right>
6 </TD>
<TD >
C </TD>
<TD align=right>
3 </TD>
<TD >
0.89% </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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|