Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Last active September 23, 2019 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandfoy/4da84f4ed2539d6a0e027d612828ca43 to your computer and use it in GitHub Desktop.
Save briandfoy/4da84f4ed2539d6a0e027d612828ca43 to your computer and use it in GitHub Desktop.
Digest ESPN's Super Bowl MVP data
#!/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