Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hey monks, I'd like to fill a database with values that I grab from 50000 html documents. There is no API available and I can't decide what method to use to parse the html structure.

Right now I have saved all the files locally (later on a direct access via web would be great) and they look like this:

... (the usual html, head, body tags, a table, some text) <table width=75%><tr><td width=50%><table width=95%><tr><td width=45% +valign=top> <table width=100% cellspacing=0 cellpadding=0><tr bgcolor=#DFDFDF><td +colspan=2 height=30><font size=4><center>tool1_name</center></font></ +td></tr> <tr bgcolor=#999999><td width=70%> <b>heading_1</b> </td><td width=30%></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>drill diameter:</font></td> + <td><font size=1>936</font></td></tr> <tr bgcolor=#CCCCCC><td><font size=1>drill depth:</font></td> + <td><font size=1>20</font></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>drill speed:</font></td> + <td><font size=1>4</font></td></tr> <tr bgcolor=#CCCCCC><td><font size=1>drill material:</font></td> + <td><font size=1>506</font></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>height:</font></td> + <td><font size=1>502</font></td></tr> <tr bgcolor=#CCCCCC><td><font size=1>width:</font></td> + <td><font size=1>6</font></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>angle:</font></td> + <td><font size=1>2.76</font></td></tr> <tr bgcolor=#CCCCCC><td><font size=1>cooling liquid:</font></td> + <td><font size=1>14</font></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>manufactured in:</font></td> + <td><font size=1>27</font></td></tr> <tr bgcolor=#CCCCCC><td><font size=1>lane code:</font></td> + <td><font size=1>76</font></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>quality test 1:</font></td> + <td><font size=1>581 (11.4%)</font></td +></tr> <tr bgcolor=#CCCCCC><td><font size=1>quality procedure:</font></td> + <td><font size=1>19,021</font></td>< +/tr> <tr bgcolor=#DFDFDF><td><font size=1>quality test 2:</font></td> + <td><font size=1>843 (90.1%)</font></td></t +r> <tr bgcolor=#CCCCCC><td><font size=1>package worth:</font></td> + <td><font size=1>$257,524</font></td></t +r> <tr bgcolor=#DFDFDF><td><font size=1>single unit worth:</font></td> + <td><font size=1>$90,945</font></td> +</tr> <tr bgcolor=#CCCCCC><td><font size=1>colour:</font></td> + <td><font size=1>48</font></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>coating:</font></td> + <td><font size=1>2,602</font></td></tr> </table><br> <table width=100% cellspacing=0 cellpadding=0><tr bgcolor=#999999><td +width=70%> <b>sells</b> </td><td width=30%></td></tr> <tr bgcolor=#DFDFDF><td><font size=1>sold this month:</font></td> + <td><font size=1>118</font></td></tr> <tr bgcolor=#CCCCCC><td><font size=1>sold in plant A:</font></td> (...)

There are about 110 unique values in 12 tables that I have to grab. On the pages are always two sets of these values: first the values (110 values in 12 tables) of a reference drill, then the values that are interesting to me.

So how do I parse these files quickly, reading all these values (stripped of dollar signs, commas, percentages) as quickly as possible?

I guess I'd use File::Slurp to store a file in a scalar, then HTML::TableExtract (How do I get the second occurrence?)? Or should I use a regex (how do I get the second occurrence?)? Or a template (how?)?

I'd be very grateful for your ideas and I really would appreciate code-snippets as I am really new to perl (replacing a bash script (yep) now...

Thanks!


In reply to how to quickly parse 50000 html documents? by brengo

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (7)
    As of 2014-07-11 10:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (224 votes), past polls