Last active
September 23, 2019 22:33
-
-
Save briandfoy/4da84f4ed2539d6a0e027d612828ca43 to your computer and use it in GitHub Desktop.
Digest ESPN's Super Bowl MVP data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Users/brian/bin/perl | |
use v5.10; | |
use Mojo::UserAgent; | |
use Mojo::Util qw(dumper); | |
my $ua = Mojo::UserAgent->new; | |
my $url = 'http://www.espn.com/nfl/superbowl/history/mvps'; | |
my $tx = $ua->get( $url ); | |
my @hashes = $tx->result->dom | |
->find( 'table tr' ) | |
->grep( sub { $_->attr('class') =~ m/\A(?:odd|even)row\z/ } ) | |
->map( sub { | |
state $n = 1; | |
my @rows = $_->find( 'td' )->map( 'text' )->each; | |
my( $player, $position, $team ) = split /\s*,\s*/, $rows[1]; | |
{ | |
superbowl => $n++, | |
player => $player, | |
position => $position, | |
team => $team, | |
description => $rows[2] | |
} | |
}) | |
->each; | |
my @table = qw(player team position); | |
foreach my $column ( @table ) { | |
say "\u$column"; | |
my $this; | |
foreach my $h ( @hashes ) { | |
$this->{ $h->{$column} }++; | |
} | |
foreach my $item ( sort { $this->{$b} <=> $this->{$a} } keys %$this ) { | |
last if $this->{$item} < 2; | |
printf "\t%2d %s\n", $this->{$item}, $item; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment