G'day epimenidecretese,

I'm not completely sure what you're after. A small, representative sample of data and expected output would have helped.

If by "pile up all the code" you mean process all of your HTML files in a single run, then yes, getting a frequency count of all the tags in all the files "is possibile in a few lines of code".

Here's pm_1082082_html_tag_count.pl:

#!/usr/bin/env perl -l use strict; use warnings; my %tags; while (<>) { ++$tags{$1} while /<(?!\/)([^ >]+)/g; } print "$_\t$tags{$_}" for sort { $tags{$b} <=> $tags{$a} } keys %tags;

Here's some dummy input data. You can view those in a browser if you want: they render OK but they're not very interesting.

$ ls -l pm_1082082_*.html -rw-r--r-- 1 ken staff 237 13 Apr 12:13 pm_1082082_1.html -rw-r--r-- 1 ken staff 237 13 Apr 12:12 pm_1082082_2.html
$ cat pm_1082082_1.html <h1 id="H-1">Heading 1</h1> <p class="sub-heading"> Some <strong>bold</strong> and <em>italic</em> text.</p> <h2 id="H-1-2">Heading 1.2</h2> <p>Para1 (1.2.1)</p><p>Para2 (1.2.2)</p> <p><strong>Fake newlines:</strong><br /><br><br /></p>
$ cat pm_1082082_2.html <h1 id="H-2">Heading 2</h1> <p class="sub-heading"> Some <strong>bold</strong> and <em>italic</em> text.</p> <h2 id="H-2-2">Heading 2.2</h2> <p>Para1 (2.2.1)</p><p>Para2 (2.2.2)</p> <p><strong>Fake newlines:</strong><br /><br><br /></p>

Here's a sample run:

$ pm_1082082_html_tag_count.pl pm_1082082_*.html p 8 br 6 strong 4 h1 2 em 2 h2 2

If that's not what you're after, you'll need to clarify what you do want and, as already mentioned, sample input and expected output will help.

[If you're unsure of what information to provide, the guidelines in "How do I post a question effectively?" should help.]

-- Ken


In reply to Re: Scrape a blog: a statistical approach by kcott
in thread Scrape a blog: a statistical approach by epimenidecretese

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.