--- title: 銀座ルノアールの店舗情報を取得 author: kazu634 date: 2009-06-21 url: /2009/06/21/_1274/ wordtwit_post_info: - 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4659;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}' categories: - Perl ---

Google Mapsにマッピングしようとして、住所情報を取得するPerlスクリプトを作成してみました(スターバックスはちょっと難しいので後でやる)。

Web::Scraperは便利だ♪

# === Libraries ===
use strict;
use warnings;
use URI;
use Web::Scraper;
use YAML;
use Encode;
use utf8;
my @address;
# === Main part ===
my $frame = scraper {
process '//td[@class="line_a" and @bgcolor="#ffffff"]//a',
'shop[]' => '@href';
};
my $res =
$frame->scrape( URI->new("http://www.ginza-renoir.co.jp/renoir/index.htm") );
# print encode('utf8', YAML::Dump($result->{body}));
foreach my $x ( @{ $res->{shop} } ) {
my $main = scraper {
process '//td[@bgcolor="#ffffff" and @align="left"]',
'shopinfo[]' => 'TEXT';
};
my $part = scraper {
process
'/html/body/center[2]/center/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody',
'shop' => $main;
result 'shop';
};
my $result = $part->scrape(
URI->new($x) );
foreach my $y ( @{ $result->{shopinfo} } ) {
push(@address, encode('utf8', $y)) if ($y =~ /^東京都/);
push(@address, encode('utf8', $y)) if ($y =~ /^神奈川県/);
}
foreach (@address) {
print("$_\n");
}
#    print encode( 'utf8', YAML::Dump($result) );
}