Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found