How many characters per character? At http://shakespeare.mit.edu/ you can find the full text of each of Shakespeare's plays on one page (e.g. Hamlet).

Write a script that takes in the url of a play from stdin, such as http://shakespeare.mit.edu/hamlet/full.html, and outputs the number of text characters each play character spoke to stdout, sorted according to who spoke the most.

The play/scene/act titles obviously do not count as dialogue, nor do the character names. Italicized text and [square bracketed text] are not actual dialogue, they should not be counted. Spaces and other punctuation within dialogue should be counted.

(The format for the plays looks very consistent though I have not looked at them all. Tell me if I've overlooked anything. Your script does not have to work for the poems.)

Example

Here is a simulated section from Much Ado About Nothing to show what I expect for output:


  More Ado About Nothing
  
  Scene 0.
  
  Messenger
  
  I will.
  
  BEATRICE
  
  Do.
  
  LEONATO
  
  You will never.
  
  BEATRICE
  
  No.


Expected output:

LEONATO 15
Messenger 7
BEATRICE 6


Scoring

This is code golf. The smallest program in bytes will win.
PHP (240 characters)

Divides the html into strings (using  as a delimeter), then runs a couple of regular expressions to extract name and words spoken. Saves length of words spoken into array.
Golfed:


&lt;?@$p=preg_match_all;foreach(explode('/bl',implode(file(trim(fgets(STDIN)))))as$c)if($p('/=s.*?b&gt;(.*?):?&lt;/',$c,$m)){$p('/=\d.*?&gt;(.*?)&lt;/',$c,$o);foreach($m[1]as$n)@$q[$n]+=strlen(implode($o[1]));}arsort($q);foreach($q as$n=&gt;$c)echo"$n $c\n";


Ungolfed:


&lt;?php
$html = implode(file(trim(fgets(STDIN))));
$arr = explode('/bl',$html);
foreach($arr as $chunk){
    if(preg_match_all('/=s.*?b&gt;(.*?):?&lt;/',$chunk,$matches)){
        $name = $matches[1];
        preg_match_all('/=\d.*?&gt;(.*?)&lt;/',$chunk,$matches);
        foreach($name as $n)
            @$names[$n] += strlen(implode($matches[1]));
    }
}
arsort($names);
foreach($names as $name=&gt;$count)
    echo "$name $count\n";


Note: This considers 'All' to be a separate character.

Example:

$php shakespeare.php &lt;&lt;&lt; "http://shakespeare.mit.edu/hamlet/full.html"
HAMLET 60063
KING CLAUDIUS 21461
LORD POLONIUS 13877
HORATIO 10605
LAERTES 7519
OPHELIA 5916
QUEEN GERTRUDE 5554
First Clown 3701
ROSENCRANTZ 3635
Ghost 3619
MARCELLUS 2350
First Player 1980
OSRIC 1943
Player King 1849
GUILDENSTERN 1747
Player Queen 1220
BERNARDO 1153
Gentleman 978
PRINCE FORTINBRAS 971
VOLTIMAND 896
Second Clown 511
First Priest 499
Captain 400
Lord 338
REYNALDO 330
FRANCISCO 287
LUCIANUS 272
First Ambassador 230
First Sailor 187
Messenger 185
Prologue 94
All 94
Danes 75
Servant 49
CORNELIUS 45