#!/usr/bin/perl
#
use LWP::UserAgent;

# create a new UserAgent instance
my $ua = LWP::UserAgent->new;

# set ua identity to Mozilla, otherwise the site won't recognize it
my @ns_headers = (
     'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
);

# get last name as a command line argument
my $cognome = $ARGV[0];
# the query is composed just by appending the last name to the following URL
my $URL = "http://www.dei.polimi.it/people/index.php?p=$cognome";

# get the page or DIE
my $res = $ua->get( $URL, @ns_headers );
die "Can't get $URL -- ", $res->status_line unless $res->is_success;

my $content = $res->content;

# if content contains the specified regexp, extract and print the section
if ($content =~ /id_sezione=.&amp;idlang=ita">([^<]*)</si){
	print "  Section : $1\n";
}
