--- title: 銀座ルノアールの場所をマッピング author: kazu634 date: 2009-07-05 url: /2009/07/05/_1290/ 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:4693;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}' categories: - Perl ---
暫定的に完成しました: 銀座ルノアール
# === Libraries === use strict; use warnings; use URI; use Web::Scraper; use YAML; use Data::Dumper; use Encode; use utf8; use HTML::Template; # use encoding "utf8", STDOUT => "utf8"; use Geography::AddressExtract::Japan; use WebService::Simple; my @address; my @array; # === 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") ); foreach my $x ( @{ $res->{shop} } ) { my $part = scraper { process '/html[1]/body[1]/center[2]/center[1]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table[@class="size2"]/tbody[1]/tr[1]/td[2]', 'shop' => 'TEXT'; process '/html[1]/body[1]/center[2]/center[1]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table[@class="size2"]/tbody[1]/tr[3]/td[2]', 'address' => 'TEXT'; }; my $result = $part->scrape( URI->new($x) ); foreach my $addr ( $result->{address} ) { my $t = Geography::AddressExtract::Japan->extract($addr); my $work = $t->[]->{"city"} . $t->[]->{"aza"} . $t->[]->{"number"}; my $latlng = &getLatLng($work); my ( $lng, $lat ) = split( /,/, $latlng ); push( @array, { lat => $lat, lng => $lng } ); } } my $tmpl = HTML::Template->new( filename => 'googlemap.tt' ); $tmpl->param( DATASET => \@array ); print $tmpl->output; sub getLatLng() { my $arg = shift(); my $geocode = WebService::Simple->new( base_url => "http://maps.google.com/maps/geo", param => { output => 'xml', hl => 'ja', ie => 'UTF8', oe => 'UTF8', } ); my $response = $geocode->get( { q => $arg, } ); if ( $response->parse_response()->{Response}->{Status}->{code} == 200 ) { return $response->parse_response()->{Response}->{Placemark}->{Point} ->{coordinates}; } else { return 'Not Found, Not Found'; } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <title>GoogleMaps Test</title> <meta name="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="http://maps.google.co.jp/maps?file=api&v=2&key=ABQIAAAAi7tMvJT0pMWzzgIPgaKRWhS4ltLnHR4dqto9lWrc1i-hPbZKVRRG70Vj11-gAnxyxcGtaalOIUBpBA" charset="utf-8"></script> <script type="text/javascript"> //<![CDATA[ var map; function startUp() { map = new GMap2( document.getElementById("mymap")); map.setCenter( new GLatLng(35.9072644, 139.4841802), 10 ); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); <TMPL_LOOP NAME=DATASET> createMarker(<TMPL_VAR NAME=lat>, <TMPL_VAR NAME=lng>); </TMPL_LOOP> function createMarker(lat, lng) { var mk = new GMarker( new GLatLng(lat, lng) ); map.addOverlay(mk); GEvent.addListener(mk, "click", function() { mk.openInfoWindowHtml( "memo" );}); } } onload = startUp; onunload = GUnload; </script> <style type="text/css"> html, body { width: 100%; height: 100%; } html { overflow: hidden; } body { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; } #top { top: 0px; left: 0px; width: 100%; height: 15%; } #mymap { width: 80%; height: 100%; } </style> </head> <body> <div id="mymap"></div> </body> <hr> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <title>GoogleMaps Test</title> <meta name="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="http://maps.google.co.jp/maps?file=api&v=2&key=ABQIAAAAi7tMvJT0pMWzzgIPgaKRWhS4ltLnHR4dqto9lWrc1i-hPbZKVRRG70Vj11-gAnxyxcGtaalOIUBpBA" charset="utf-8"></script> <script type="text/javascript"> //<![CDATA[ var map; function startUp() { map = new GMap2( document.getElementById("mymap")); map.setCenter( new GLatLng(35.9072644, 139.4841802), 10 ); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); createMarker(35.7320865, 139.7138439); createMarker(35.7321420, 139.7128801); createMarker(35.7331675, 139.7398948); createMarker(35.7080096, 139.7599332); createMarker(35.6197692, 139.7293858); createMarker(35.7067903, 139.6663186); createMarker(35.7081818, 139.6653381); createMarker(35.6733528, 139.7675810); createMarker(35.6739055, 139.7669699); createMarker(35.6727390, 139.7676699); createMarker(35.6723169, 139.7690560); createMarker(35.6727445, 139.7652145); createMarker(35.6688283, 139.7642480); createMarker(35.6685117, 139.7676728); createMarker(35.6814104, 139.7726638); createMarker(35.6852072, 139.7762885); createMarker(35.6813936, 139.7699945); createMarker(35.6810853, 139.7702779); createMarker(35.5889452, 139.7292928); createMarker(35.5612929, 139.7148402); createMarker(35.7078879, 139.7760349); createMarker(35.7109514, 139.7743599); createMarker(35.7100098, 139.7731878); createMarker(35.7276245, 139.7689179); createMarker(35.6903637, 139.7361271); createMarker(35.6992491, 139.7452177); createMarker(35.7017628, 139.7515561); createMarker(35.6910813, 139.7685749); createMarker(35.6927284, 139.7706636); createMarker(35.6912064, 139.7712053); createMarker(35.6738081, 139.7604648); createMarker(35.6973334, 139.7726883); createMarker(35.6995304, 139.7710245); createMarker(35.6978834, 139.7747021); createMarker(35.7058512, 139.6505642); createMarker(35.6903875, 139.6958309); createMarker(35.6893044, 139.6982473); createMarker(35.6927540, 139.6981833); createMarker(35.6943759, 139.6943865); createMarker(35.6911878, 139.7078073); createMarker(35.6907822, 139.7056270); createMarker(35.6926912, 139.7355798); createMarker(35.6862696, 139.7289917); createMarker(35.6945067, 139.7035410); createMarker(35.6945705, 139.7019745); createMarker(35.6950454, 139.7004413); createMarker(35.6941316, 139.6992943); createMarker(35.6949732, 139.6981916); createMarker(35.7016167, 139.6955250); createMarker(35.7018002, 139.6991329); createMarker(35.7139962, 139.7050011); createMarker(35.7125354, 139.7071981); createMarker(35.7121909, 139.7042068); createMarker(35.7119659, 139.7041790); createMarker(35.6816777, 139.7019528); createMarker(35.6809585, 139.7100715); createMarker(35.6560085, 139.7015788); createMarker(35.6591388, 139.7043812); createMarker(35.6620215, 139.6972123); createMarker(35.6614745, 139.7025757); createMarker(35.7321156, 139.7675873); createMarker(35.7282051, 139.7721982); createMarker(35.6763293, 139.7366666); createMarker(35.6648119, 139.7562514); createMarker(35.6684642, 139.7571124); createMarker(35.6462388, 139.7470472); createMarker(35.6567100, 139.7538879); createMarker(35.6290796, 139.7429121); createMarker(35.6304154, 139.7378514); createMarker(35.6976951, 139.8253644); createMarker(35.7704183, 139.8711235); createMarker(35.6966468, 139.4146625); createMarker(35.6987800, 139.4151235); createMarker(35.7009965, 139.4155373); createMarker(35.7038828, 139.5603612); createMarker(35.4413525, 139.6502110); createMarker(35.4441327, 139.6367062); createMarker(35.4436606, 139.6320260); createMarker(35.5082843, 139.6776540); createMarker(35.3194949, 139.5511114); createMarker(35.3537686, 139.5323658); createMarker(35.5297282, 139.6991820); createMarker(35.5314140, 139.7010568); createMarker(35.2308553, 139.1015186); createMarker(35.9072644, 139.4841802); createMarker(35.7223281, 139.9278380); function createMarker(lat, lng, memo) { var mk = new GMarker( new GLatLng(lat, lng) ); map.addOverlay(mk); GEvent.addListener(mk, "click", function() { mk.openInfoWindowHtml( memo );}); } } onload = startUp; onunload = GUnload; </script> <style type="text/css"> html, body { width: 100%; height: 100%; } html { overflow: hidden; } body { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; } #top { top: 0px; left: 0px; width: 100%; height: 15%; } #mymap { width: 80%; height: 100%; } </style> </head> <body> <div id="mymap"></div> </body> <hr> </body> </html>