#!/usr/bin/perl use CGI qw(:standard); use LWP::Simple qw/get/; use HTML::Parse; use HTML::Element; use URI::URL; $what = param("txtStreet"); # output a document print header(), start_html("Christchurch Map for $what"), p("

Christchurch Map for $what

You typed: ", tt(escapeHTML($what))), "
"; #end_html(); $get_maps = "http://www.ccc.govt.nz/webapps/wisesstreet/frmWisesMapSearch.asp?txtStreet=$what&cmdSubmit=Search"; #print "$get_maps\n"; $html_for_maps = get ($get_maps); $parsed_html_map = parse_html($html_for_maps); $getmap_list = "http://www.ccc.govt.nz/maps/wises/Map"; $count=0; for (@{ $parsed_html_map->extract_links() }) { $link=$_->[0]; $url = new URI::URL $link; $full_url_map = $url->abs($url); #print "$full_url_map\n"; $suburl=substr($full_url_map, 0, 37); if ($suburl=~$getmap_list) { $count++; $this_one = $full_url_map; print "Map $count - $full_url_map
"; create_list($this_one); } } sub create_list { $url = $this_one; #print "$url\n"; $length = length($url); #test if coordy is a single or double letter $coordy_test = substr($url, -2); #print "$coordy_test\n"; $coordy_test2 = substr($coordy_test, 0, 1); #print "$coordy_test2\n"; if ($coordy_test2 =~ "=") { $coordy = substr($url, -1); } else { $coordy = substr($url, -2); } print "$coordy\n"; $url2 = substr($url, 0, $length-9); #print "$url2\n"; #test if coordx is long enough $coordx_test = substr($url2,-1); # print "$coordx_test\n"; if ($coordx_test =~ "&") { $coordx_test2 = substr($url2,-3); $coordx = substr($coordx_test2, 0, 2); #$coordx = substr($url, -1); } else { $coordx_test3 = substr($url2, -2); $coordx_test4 = substr($coordx_test3, 0, 1); #print "$coordx_test4\n"; if ($coordx_test4 =~ "="){ $coordx = substr($coordx_test3, -1); } else { $coordx = substr($coordx_test3, -2); } } print "$coordx\n"; $getmap = "imagecoords=$coordy%20$coordx"; $html = get ($url); $parsed_html = parse_html($html); ## Make links full URL's, then isolate the map link for (@{ $parsed_html->extract_links() }) { $link=$_->[0]; $url = new URI::URL $link; $full_url = $url->abs($url); #print "$full_url
"; # test if inner city or suburb $length_fullurl = length($full_url); $inner_temp1 = substr($full_url, $length_fullurl-2); #print "$inner_temp1
"; $inner_temp2 = substr($inner_temp1, 0, 1); #print "$inner_temp2
"; if ($inner_temp2 == "'") { $suburl=substr($full_url,-20); } else { $suburl=substr($full_url,-28); } $suburl_length=length($suburl); #print "$suburl
"; $suburl2=substr($suburl, 0, $suburl_length-2); #print "$suburl2
"; #test if i is at start of imagecoords $test_if_i=substr($suburl2, 0, 1); if ($test_if_i !~ "i") { $suburl2="i$suburl2"; } if ($suburl2=~$getmap) { #print "$full_url\n"; $mapurl_temp1 = substr($full_url,27); $length_mapurl_temp1 = length($mapurl_temp1); #print "$mapurl_temp1\n"; $mapurl_temp2 = substr($mapurl_temp1, 0, $length_mapurl_temp1-2); print "Click here for map

"; } } } print end_html();