Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://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":



  • 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 scrutinizing the Monastery: (6)
As of 2024-04-19 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found