#!/usr/bin/perl -w use strict; use Web::Scraper; use URI; use Template; use CGI qw( :all ); print header( -type => 'application/vnd.google-earth.kml+xml', -content_location => 'microformat.kml', -access_control_allow_origin => '*', -expires => '-1d', ); my $url = "http://en.wikipedia.org/wiki/ . "Us_national_parks"; my $coords = scraper { process 'span.vcard', 'vcards[]' => scraper { process '.geo', geo => 'TEXT'; process '.org', name => 'TEXT'; } }; my $res = $coords->scrape( URI->new( $url ) ); my @parks = (); for my $vcard ( @{ $res->{ vcards } } ) { next unless exists $vcard->{ geo }; my( $lon, $lat ) = split /\s*;\s*/, $vcard->{ geo }; push @parks, { name => $vcard->{ name }, lat => $lat, lon => $lon }; } my $tmpl = Template->new(); my $data = join( '', ); binmode STDOUT, ":utf8"; $tmpl->process( \$data, { parks => \@parks } ) || die $tmpl->error(); __DATA__ US National Parks [% FOR park IN parks %] [% park.name %] [% park.lat %], [% park.lon %], 0 [% END %]