Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created August 29, 2012 18:23
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/3516601 to your computer and use it in GitHub Desktop.
Save briandfoy/3516601 to your computer and use it in GitHub Desktop.
Extract Looney Toons links
#!/usr/local/perls/perl-5.14.2/bin/perl
use v5.14;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
my $url = 'http://www.toonarific.com/show_episodes.php?show_id=2177';
my @seasons = $ua->get( $url )
->res
->dom
->find( 'select > option' )
->grep( sub { $_->{value} =~ m/&season=([0-9]+)&/ } )
->map( sub {
my( $season ) = $_->{value} =~ m/&season=([0-9]+)&/;
{
id => $season,
year => $_->text,
}
}
)
->each;
my @grand_links;
foreach my $season ( @seasons ) {
state $url_format = 'http://www.toonarific.com/show_episodes.php?show_id=2177&season=%s&show_rank=-1';
my $url = sprintf $url_format, $season->{id};
my $tx = $ua->get( $url );
my @links = $tx->res
->dom
->find( 'a' )
->grep( sub { $_->{href} =~ /episode_id=[0-9]+/ } )
->map( sub {
my( $episode ) = $_->{href} =~ /episode_id=([0-9]+)/;
my( $text ) = $_->text;
$text =~ s/\s+/ /g;
{
year => $season->{year},
season => $season->{id},
episode => $episode,
href => $_->{href},
title => $text
}
}
)
->each
;
push @grand_links, @links;
}
my @keys = qw( season episode title year href );
say join "\t", @keys;
foreach my $link ( @grand_links ) {
say join "\t", @{ $link }{ @keys };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment