今日のNMB48
Web::Scraperで、AKBやSKEのスケジュールを取ってきているブログのエントリがあったので、NMBでもやってみました。
Web::Scraper便利。
#!/usr/bin/env perl use strict; use warnings; use utf8; use Encode; use Time::Piece; use URI; use Web::Scraper; my $now = localtime; my $date = $now->date(''); my $year = substr($date, 0, 4); my $mon = substr($date, 4, 2); my $today = $now->mday; my $url = 'http://www.nmb48.com/schedule/' . $year . '_' . $mon . '.html'; my %category = ( stage => '公演', media => 'メディア', event => 'イベント', etc => 'その他', ); my $schedule = scraper { process '//table[@title="月間スケジュール"]/tr', 'tr[]', => scraper { process '//th', 'date' => 'TEXT'; process '//td/ul/li', 'td[]' => scraper { process 'li', 'category' => '@class'; process 'li', 'event' => 'TEXT'; process 'a', 'link' => '@href'; }; }; }; my $res = $schedule->scrape( URI->new($url) ); for my $tr (@{$res->{tr}}) { (my $day = $tr->{date}) =~ s/^(\d+).*/$1/; next unless ($day == $today); for my $td (@{$tr->{td}}) { my $category = $category{$td->{category}}; print encode('utf-8', "\[$category\] "); print encode('utf-8', $td->{event}), "\n"; print encode('utf-8', $td->{link}), "\n" if (defined($td->{link})); } }
output
[その他] NMB48劇場休館日 http://www.nmb48.com/news/etc/etc_2011_05_23_02.html [メディア] 6:30-9:00 ラジオ日本「おはようスプーン」(山本/渡辺) http://www.nmb48.com/news/media/media_2011_05_31_04.html [メディア] 18:07- FM大阪「NMB48のりっすんぷりーず!」 [メディア] 19:00-19:55 NTV「なるほど!ハイスクール」(山本/渡辺) [メディア] 24:55-25:40 MBS「やかせて!ソーセージ」