Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

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

For counterpoint, I ran your snippet through the following one liner and got pretty much what you need:

>perl -nle"m[<font size=1>([^<]+)</font></td></tr>] and print $1" junk +.txt 936 20 4 506 502 6 2.76 14 27 76 581 (11.4%) 19,021 843 (90.1%) $257,524 $90,945 48 2,602 118

Your description says each page consists of two same-sized set of these values, so just discard the first half. You don't want the dollar signs, commas or percentages, so post process to remove them.

People will tell you that this is fragile, and will break if the page is changed. But any solution will break if the pages change, but given how simple this is, it'll will probably be quicker to fix this, than any solution that relies upon fuzzy parsing of a whole heap of stuff that you have no interest in whatsoever.

Just as I don't bother reading the stories on the newspaper my fish&chips comes wrapped in before eating; I don't bother parsing a bunch of html I've no interest in. Ie. Don't parse; simply extract.

It will certainly be a whole heap faster. Given your description of the size of the files, I estimate that the above should be able to process each page in about 1/20th of a second, giving you a total time of about 40 minutes instead of your current 28hrs.

Update: I revise my estimate to just over 3 minutes based upon running this code:

#! perl -nlw use strict; use Time::HiRes qw[ time ]; BEGIN{ @ARGV = map glob, @ARGV } local $/; my $start = time; while( <> ) { my @vals; while( m[<font size=1>([^<]+)</font></td></tr>]g ) { my $val = $1; $val =~ tr[$,][]d; $val =~ s[^\s*([0-9.]+).+$][$1]e; push @vals, $val; } print "@vals[ @vals /2 .. $#vals ]"; } print time-$start;

Over 1000 copies of a mocked up file containing 10 copies of your snippet (5 as the reference; 5 as the wanted) in 4 seconds:

C:\test>873713 junk*.txt ... 93 2 4 50 50 6 2.7 1 2 7 581 1902 843 25752 9094 4 260 93 2 4... 93 2 4 50 50 6 2.7 1 2 7 581 1902 843 25752 9094 4 260 93 2 4... 93 2 4 50 50 6 2.7 1 2 7 581 1902 843 25752 9094 4 260 93 2 4... 93 2 4 50 50 6 2.7 1 2 7 581 1902 843 25752 9094 4 260 93 2 4... 4.07200002670288 ^Z

Even if the page layout changes, the 27 hrs 57 minutes you saved each time you need to do this, should cover the 5 minutes it will take to re-write it :)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: how to quickly parse 50000 html documents? (Updated: 50,000 pages in 3 minutes!) by BrowserUk
in thread 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 browsing the Monastery: (7)
    As of 2014-12-27 02:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (176 votes), past polls