Sang has asked for the wisdom of the Perl Monks concerning the following question:
Given this Census area selection page how could I modify the code below to also display the area names, e.g., "Tulsa, OK (city) STF3A" instead of just "STF3A"?
How to make a self-contained CGI script to dynamically generate these pages instead of saving them to disk? I realize that's a big question but, mebbe someone could show a little example? Type an address in a form and it retrieves and displays the page changing any occurance of "the" to "tha", etc?
use URI::URL; use LWP::Simple; use HTML::TokeParser; use strict; my $url = url('http://www.census.gov/cgi-bin/gazetteer'); $url->query_form( city => "Tulsa", state => "OK" ); my $document = get( $url ); my $p = HTML::TokeParser->new(\$document); open( OUTPUT, ">output.html" ) || die "Couldn't open 'output.html': $! +\n"; while (my $token = $p->get_tag("a")) { my $url = $token->[1]{href}; $url =~ s/CMD=TABLES/CMD=RET/; my $text = $p->get_trimmed_text("/a"); if ($text eq "STF1A" || $text eq "STF3A") { print OUTPUT "<a href=$url/FMT=HTML/T=P1>$text</a><BR>\n"; } } close( OUTPUT ) || die "Can't close 'output.html': $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Retreive, modify, & display webpage
by AidanLee (Chaplain) on Jan 03, 2002 at 19:57 UTC | |
by Sang (Acolyte) on Jan 03, 2002 at 23:33 UTC | |
by AidanLee (Chaplain) on Jan 04, 2002 at 00:21 UTC | |
by Sang (Acolyte) on Jan 04, 2002 at 00:45 UTC |