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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |