Enclosed is a long perl script :
I am unable to assign any value to a SELECT type of
field which has been set to 'multiple'. Given below is
the error.
=============
Illegal value 'FULLTIME' at ./dice.pl line 407
I am a newbie so please comment on the remaining
script for style etc.
Thanx in advance to all guru's.
Charu Palkar
--
PS : This is the error even after upgarding to
'libwww-5.69'
--
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
#!/usr/bin/perl -w
#
# File dice.pl
#
# Description : To retrive information about job postings from
# "www.dice.com" for a given search criteria. The user will
# provide the following information -
# a) Words to search in a text
# b) type of search for (a)
# - all words
# - any word
# - boolean expression [ deferred implementaion ]
# c) Range of search
# - Days back (default 30 days) [1,2,7,10,14,21,30]
# - Number of jobs listed per page (default 50) [10,20,30,40,50]
# d) Tax terms
# - No restrictions (default)
# - Contract - W2
# - Contract to hire - W2
# - Full time
# - Contract - Independent
# - Contract to hire - Independent
# - Contract - Corp to corp
# - Contract to hire - Corp to corp
# e) Location
# - Country (Default:USA)
# - States (Default:NJ)
# f) Options
# - Travel (default:None) [none,25%,50%,75%,100%]
# - Telecommute (default:no)
# g) Search area list of area codes (default:none)
#
# Usage : dice.pl [-h] [-v] [-w <word>] [-s a|l|b]
# [-d 1|2|7|10|14|21|30] [-l 10|20|30|40|50]
# [-t C2|ch2|ft|ci|chi|cc|chc]
# [-c <country code>] [-p <province/state code>]
# [-T n|25|50|75|100] [-C] [-o <filename>]
#
# Option descriptions :
# h - Help message
# v - print version
# w - search words can be repeated must be followed by a string
# s - search type a=all words y=any word b=boolean expression
# d - number of days
# l - number of jobs per page
# t - tax terms c2 = contract on W2
# ch2 = contract to hire on W2
# ft = full time
# ci = contract independent
# chi = contract to hire independent
# cc = contarct corp to corp
# chc = contract to hire corp to corp
# c - Country code (two letter)
# p - State/provencial code (two letter)
# T - Amount of travel n = none all numbers are percentages
# a - Restrict search to these area code
# C - Telecommute
# o - Output file filename
# Note : If file with filename exists a warning will is
# the file is moved to "filename.<DATE-TIME>.OLD"
#
# Algorithm :
# a) Retrieve command line options
# b) If help flag then display help message and exit
# c) Validate all options and assign to global data
# d) Setup LWP UserAgent - web browser handle
# e) Setup initial request to retrieve query from
# f) Execute request and retrieve query from
# g) Extract query from from Response object
# h) Fillin query from
# i) Execute form
# j) For every page in search result
# ( create request if next page link and execute to retrive )
# 1) For every link to job posting
# i) Construct and excute request
# ii) Extract contact info and write to file
#------------------------------------------------------------------------------
use strict;
use Getopt::Long; # To extract comand line options
use LWP; # Don't know why but need for cookie
use LWP::UserAgent; # Virtual browser
use HTML::Form; # HTML form
my %input_values; # Input field values indexed by @input_fields
my @input_fields =
(
'FREE_TEXT', # Description
'SEARCH_INCLUDE', # Search conditions
'DAYSBACK', # Days back to search for
'NUM_PER_PAGE', # Jobs per page to display
'TAXTERM', # Job type contract/employment (multiple)
'STAT_PROV', # State/Province (multiple)
'COUNTRY', # Country
'REQ_TRAVEL', # Amount(percentage) of travel
'TELECOMMUTE', # Telecommute flag
'AREA_CODES', # Phone area codes to restrict search
'ABBR_RESULTS', # Abbrevated result display
'HOTRESULTS' # Search button
);
my %srch_list =
(
'a' => 'AND', # All word
'y' => 'OR', # Any word
'b' => 'BOOL' # Boolean expr
);
my $def_srch = $srch_list{'a'}; #default search
my %days_list = # number of days previous
(
1 => '1',
2 => '2',
7 => '7',
10 => '10',
14 => '14',
21 => '21',
30 => '30'
);
my $def_days = $days_list{30}; #default days
my %job_list = # Number of jobs per page
(
10 => '10',
20 => '20',
30 => '30',
40 => '40',
50 => '50'
);
my $def_jobs = $job_list{10}; #default jobs per page
my %tax_list = # Employment type
(
'all' => 'ALL', # All possible
'c2' => 'CON_W2', # contract on W2
'ch2' => 'CON_HIRE_W2', # contract to hire on W2
'ft' => 'FULLTIME', # full time
'ci' => 'CON_IND', # contract independent
'chi' => 'CON_HIRE_IND', # contract to hire independent
'cc' => 'CON_CORP', # contarct corp to corp
'chc' => 'CON_HIRE_CORP' # contract to hire corp to corp
);
my $def_tax = $tax_list{'all'}; #default employment type
my %trvl_list = # Amount of travel
(
0 => '1', # no travel
25 => '26',
50 => '51',
75 => '76',
100 => '101'
);
my $def_trvl = $trvl_list{0}; #default amount of travel
# List of variables for options
my $help_flg; # Help message
my $ver_flg; # print version
my $word_list; # Search word list
my $srch_flg = $def_srch; # search type
my $days_flg = $def_days; # number of days
my $jobs_flg = $def_jobs; # number of jobs per page
my $tax_flg = $def_tax; # tax terms c2 = contract on W2
my $country_flg = 'US'; # Country code (two letter)
my $prov_flg = 'NJ'; # State/provencial code (two letter)
my $trvl_flg = $def_trvl; # Amount of travel
my $acode_list; # Search restricted by area code
my $tele_flg = 0; # Telecommute
my $out_flg = 'DICE.REP'; # Output file filename
my %options_list =
(
'h' => \&print_help, # Help message
'v' => \&print_ver, # print version
'w=s' => \&mk_word_list, # Search word list
's=s' => \&mk_srch_type, # search type
'd=i' => \&mk_days_type, # number of days
'l=i' => \&mk_jobs_type, # number of jobs per page
't=s' => \&mk_tax_type, # tax terms c2 = contract on W2
'c=s' => \$country_flg, # Country code (two letter)
'p=s' => \$prov_flg, # State/provencial code (two letter)
'T=s' => \$trvl_flg, # Amount of travel
'a=i' => \&mk_acode_list, # Area code list
'C=s' => \$tele_flg, # Telecommute
'o=s' => \$out_flg # Output file filename
);
#
# Print application version
#
sub print_ver
{
my $ver = "0.01";
print "Version : $ver\n";
exit 0;
}
#
# Print help screen
#
sub print_help
{
print "TODO - help screen!\n";
exit 0;
}
#
# Warning about options
#
sub warn_opts
{
print "Warning : Invalid option value $_[1] ignored for option -$_[0]!";
}
#
# Build word list (callback)
#
sub mk_word_list
{
$word_list .= $_[1] . " " if $_[0] eq 'w';
}
#
# Search type (callback)
#
sub mk_srch_type
{
return if ( !( $_[0] eq 's' ));
if ( exists( $srch_list{$_[1]} ))
{
$srch_flg = $srch_list{$_[1]};
}
else
{
&warn_opts($_[0],$_[1]);
}
}
#
# Days to search (callback)
#
sub mk_days_type
{
return if ( !( $_[0] eq 'd' ));
if ( exists( $days_list{$_[1]} ))
{
$days_flg = $days_list{$_[1]};
}
else
{
&warn_opts($_[0],$_[1]);
}
}
#
# jobs to search (callback)
#
sub mk_jobs_type
{
return if ( !( $_[0] eq 'l' ));
if ( exists( $job_list{$_[1]} ))
{
$jobs_flg = $job_list{$_[1]};
}
else
{
&warn_opts($_[0],$_[1]);
}
}
#
# employment type to search (callback)
#
sub mk_tax_type
{
return if ( !( $_[0] eq 't' ));
if ( exists( $tax_list{$_[1]} ))
{
$tax_flg = $tax_list{$_[1]};
}
else
{
&warn_opts($_[0],$_[1]);
}
}
#
# employment based travel to search (callback)
#
sub mk_trvl_type
{
return if ( !( $_[0] eq 'T' ));
if ( exists( $trvl_list{$_[1]} ))
{
$trvl_flg = $trvl_list{$_[1]};
}
else
{
&warn_opts($_[0],$_[1]);
}
}
#
# Build area code list (callback)
#
sub mk_acode_list
{
return if ( !( $_[0] eq 'a' ));
if ( $_[1] =~ /^\d+$/ )
{
$acode_list .= $_[1] . " ";
}
else
{
&warn_opts($_[0],$_[1]);
}
}
#
# Check for output/report file if it exists save it
# by moving it to 'filename.<DATE-TIME>.OLD'
#
sub set_outf
{
my $fn = $_[0]; # file name
if ( -f $fn ) # file exists rename it
{
my @dt = localtime(time()); # current time
rename($fn,sprintf("$fn.%02d%02d-%02d%02d%02d.OLD",$dt[4]+1,$dt[3],$dt[2],$dt[1],$dt[0]));
}
}
Getopt::Long::Configure('debug'); # Enable debug
Getopt::Long::Configure('posix_default'); # Enable single char options
Getopt::Long::Configure('bundling'); # Enable concat of single char options
GetOptions( %options_list );
# TODO : Display all options selected and prepare report file
die "Exiting no words specified for search ... \n" if ! $word_list;
set_outf($out_flg); # Check and setup output file
die "ERROR : Unable to create report file $out_flg\n" if ! open(D_REP,"> $out_flg");
print "\n\tSEARCH SEPCIFICATION\n";
print "WORD(s) : ",$word_list, "\n" if $word_list;
print "SEARCH CONDITION : ", $srch_flg, "\n";
print "DAYS RANGE : ", $days_flg, "\n";
print "JOBS PER PAGE : ", $jobs_flg, "\n";
print "EMPLOYMENT TYPE : ", $tax_flg, "\n";
print "COUNTRY : ", $country_flg, " (not validated)\n";
print "PROV/STATE : ", $prov_flg, " (not validated)\n";
print "TRAVEL : ", $trvl_flg, "%\n";
print "AREA CODE(s) : ",$acode_list, "\n" if $acode_list;
print "TELECOMMUTE : ",( $tele_flg ? "YES" : "NO" ), "\n";
print "REPORT FILE : ", $out_flg , "\n";
# TODO : Create browser
# a) Setup user agent
# b) Initialize HTTP header
my $br = LWP::UserAgent->new(); # Create virtual browser
$br->agent('Charu/0.1 ');
$br->from('[EMAIL PROTECTED]');
$br->cookie_jar( { file => 'cookie.csp' } );
# TODO : Create request to retrieve form
my $dice_url = 'http://seeker.dice.com/jobsearch/index.jsp'; # Dice job search URL
my $req = HTTP::Request->new( GET => $dice_url ); # Request init
$req->header( 'Accept' => 'text/html');
# TODO : Execute request and check for sucess
# a) Display return code
# b) Display contents (form expected)
my $res = $br->request($req); # Request made
die "Request error : ", $res->status_line," !\n" if ( $res->is_error ); # Request
failed
print "Response is : ", $res->content(),"\n";
my $job_fm = HTML::Form->parse($res->content(),$res->base()); # Construct from
die "Error : No form found!\n" if ( !$job_fm );
print "Form method : ", $job_fm->method(), "\n";
print "Form action : ", $job_fm->action(), "\n";
my @in_list = $job_fm->inputs(); # get input list
warn "No inputs in form!\n" if ! @in_list;
print "Form inputs : ", $#in_list, "\n";
for ( my $i = 0 ; $i <= $#in_list ; $i++ )
{
print "Input : ", $in_list[$i]->name, " ", $in_list[$i]->type;
print " ", $in_list[$i]->value if $in_list[$i]->value;
if ( $in_list[$i]->name eq 'DAYSBACK' )
{
my $old = $in_list[$i]->value;
print "\n=============\n";
$in_list[$i]->value('10');
print " ", $in_list[$i]->value, "\n";
$in_list[$i]->value($old);
print " ", $in_list[$i]->value, "\n";
print "\n=============\n";
}
if ( $in_list[$i]->name eq 'TAXTERM' )
{
my $old = $in_list[$i]->value;
print "\n=============\n";
$in_list[$i]->value('FULLTIME');
print " ", $in_list[$i]->value, "\n";
$in_list[$i]->value($old);
print " ", $in_list[$i]->value, "\n";
print "\n=============\n";
}
my @val_list = $in_list[$i]->possible_values(); # Possible values
print " (" if @val_list;
for ( my $j = 0 ; $j <= $#val_list ; $j++ )
{
print " ", $val_list[$j] if $val_list[$j];
}
print " )" if @val_list;
print "\n";
}
# TODO : Populate form and submit request
# a) Check if all fields are available
# b) Populate fields
# c) Submit request
for( my $i = 0 ; $i <= $#input_fields ; $i++ )
{
die "ERROR : Input ($input_fields[$i]) field not found!\n" if !
$job_fm->find_input($input_fields[$i]);
}
print "All fields are in form!\n";
$job_fm->value('FREE_TEXT',$word_list) if $word_list;
$job_fm->value('SEARCH_INCLUDE',$srch_flg) if $srch_flg;
$job_fm->value('DAYSBACK',$days_flg) if $days_flg;
$job_fm->value('NUM_PER_PAGE',$jobs_flg) if $jobs_flg;
$job_fm->value('NUM_PER_PAGE',"50");
$job_fm->value('TAXTERM',$tax_flg) if $tax_flg;
$job_fm->value('TAXTERM','FULLTIME');
$job_fm->value('STAT_PROV',$prov_flg) if $prov_flg;
$job_fm->value('COUNTRY',$country_flg) if $country_flg;
$job_fm->value('REQ_TRAVEL',$trvl_flg) if $trvl_flg;
$job_fm->value('TELECOMMUTE',$tele_flg) if $tele_flg;
$job_fm->value('AREA_CODES',$acode_list) if $acode_list;
print "All fields set!\n";
$req = $job_fm->click('HOTRESULTS');
my $res = $br->request($req); # Request made
die "Request error : ", $res->status_line," !\n" if ( $res->is_error ); # Request
failed
print "Response is : ", $res->content(),"\n";
# TODO : Verify response if error display message
# a) Extract links to job pages
# for each job page extract and write all details to report file
# - Job ID
# - Position
# - Contact info : email address, phone number(s)
# b) Extract link for next page and request it