How do I download webpage and parse information using Perl

I need to produce a perl program that will display information from a website. I would like to have 7 columns: Date, Time, Name, Address, DOB, Officer(s), Location


The wesbsite the html information is coming from is: http://www.iowa-city.org/police/arrests.asp?charge=94000

This how I started the Perl program. If anyone could help me out, that would be great




#!/usr/bin/perl -w
 
use strict;
use LWP::Simple;
 
my $stuff = get("http://www.iowa-city.org/police/arrests.asp?charge=94000");
 
my $columnTitle = ("Date, Time, Name, Address, DOB, Officer(s), Location\n");
 
print $columnTitle

Open in new window

MsSchlienAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kawasCommented:
0
marchentCommented:
I guess none will write the whole code for you at EE as I'm. What i can suggest you watch the attached sample code. This portion of code will parse the TITLE from the HTML of your link. I use regular expression. Just learn more about regular expression from http://www.perl.com/doc/manual/html/pod/perlre.html and http://www.cs.tut.fi/~jkorpela/perl/regexp.html and think yourself how to write regex to accomplish your task.
#!/usr/bin/perl -w
 
use strict;
use LWP::Simple;
 
my $stuff = get("http://www.iowa-city.org/police/arrests.asp?charge=94000");
 
## A simple regex that will parse the title from the page
if( $stuff =~ /<title>(.*?)<\/title>/i ){
    print "$1\n";
}

Open in new window

0
MsSchlienAuthor Commented:
Thank you, I have looked over the links and they are very helpful. However, could you maybe do an example either through psuedo-code or perl as how to obtain the first name from the table on website.
0
kawasCommented:
here is code to get the names (its quick and dirty, but you should get the idea)
use HTML::TokeParser;
use Data::Dumper;
use LWP::Simple;
 
use strict;
 
my $stuff = get("http://www.iowa-city.org/police/arrests.asp?charge=94000");
 
my $p     = HTML::TokeParser->new( \$stuff ) or die "Can't open: $!";
my $start = 0;
my @names = ();
while ( my $token = $p->get_tag("tr") ) {
	if ($start) {
		# first column is the name and addr
		$token = $p->get_tag("td");
		$p->get_tag("b");
 
		push @names, $p->get_trimmed_text()
		  if $token->[1]{nowrap} eq 'nowrap'
			  and $token->[1]{valign} eq 'top'
			  and $token->[1]{style}  eq 'font-size: 8pt;';
	}
	if ( not $start ) {
		$start = 1 if $token->[1]{bgcolor} eq 'navy';
	}
}
print Dumper(\@names);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MsSchlienAuthor Commented:
Thank you, this helped a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.