Web::Scraperに入門

遅れぎみですが、流行に乗って Web::Scraperを使ってみた。わーぃ。

#!/usr/bin/perl

use strict;
use warnings;

use URI;
use Web::Scraper;
use Data::Dumper;
use Encode;

my $girls = scraper {
    process "div table.NeoOnGirl_table" , 'items[]' => scraper {
        process "div.NeoOnGirl_oncheck img", 'status' => sub {
            my $src = $_->attr('src') ;
            $src =~ /icon_(\w+)n\./;
            return $1;
        };
        process "td.NeoOnGirl_Name", 'name' => sub {
            my $text = $_->as_text();
            encode( 'utf-8' ,$text );
        };
        process "a" ,'id' => sub {
            my $text = $_->attr('onclick');
            $text =~ /(\d+)/;
            return $1;
        };
    };
}->scrape( URI->new('http://acam.jp/acam/home1.jsp') );

warn Dumper $girls;