#! /local/bin/perl use strict; use diagnostics; use HTTP::Request::Common; use LWP::UserAgent; use CGI; my $proxy; my $jobserve ="class=\"Search\"\\s*href=\"(.*?)\">(.*?)\s*<\/a>"; my $monster = "MNSEven\">(.*?)<\/a>"; my $exp = "#f7f7f7\">.*?(.*?)<\/a>"; my $rcIreland = "jobsearchtitle\">(.*?)<\/span>.*?more details"; my $startParse =""; my $data; my $title; my $link; my @titles; my @links; my $sites = {}; my @siteInfo; my $jobs ={}; my $buffer =""; my $keyword = ""; my $englishKeyword = ""; my $escapedKeyword = ""; # make stdout hot. my $ofh = select STDOUT; $| = 1; select $ofh; if (defined $ENV{"QUERY_STRING"}) { $buffer = $ENV{"QUERY_STRING"}; if($buffer) { $buffer =~ /keyword=(.*)/i; if($1) { $keyword = $1; $englishKeyword .= $keyword; $englishKeyword =~ s/%([A-Fa-f\d]{2})/chr hex $1/eg; $escapedKeyword = $englishKeyword; $escapedKeyword =~ s/\+/\\+/g; $escapedKeyword =~ s/\?/\\?/g; logUserInfo(); } } } sub logUserInfo { my $q = new CGI; my $remoteHost = $q->remote_host(); my $referrer = $q->referer(); my $userName = $q->user_name(); my $time = localtime(); open(LOG, ">>/webtree/s/shimoda/logs/jobSearchLog.txt"); print LOG "[$time] - $remoteHost,$englishKeyword,$userName,$referrer\n"; } sub enc { my ($word) = $_[0]; $word =~ s/([^\w()'*~!.-])/sprintf '%%%02x', $1/eg; return $word; } sub dec { my ($word) = $_[0]; $word =~ s/%([A-Fa-f\d]{2})/chr hex $1/eg; return $word; } sub setupSites() { my @proxies; push(@proxies,'http://proxy1.dcu.ie:3128'); push(@proxies,'http://proxy2.dcu.ie:3128'); push(@proxies,'http://proxy3.dcu.ie:3128'); my $ua = LWP::UserAgent->new; foreach my $p (@proxies) { $ua->proxy(['http', 'ftp'], $p); my $res = $ua->request(GET "http://www.redbrick.dcu.ie"); if($res->is_success) { $proxy = $p; last; } } my $entry = {}; $entry->{PARSE} = $monster; $entry->{URL} = "http://jobsearch.monster.ie"; my $varz="brd=1\&cy=IE\&jt=2\&jt=1\&jt=4\&jt=3\&q=$keyword\&sort=rv&vw=d"; $entry->{FETCH} ="http:\/\/jobsearch\.monster\.ie/jobsearch.asp\?$varz"; $entry->{NUM_JOBS} = 0; push @{ $sites->{"www.monster.ie"}->{ENTRIES}}, $entry; $entry = {}; $entry->{PARSE} = $exp; $entry->{URL} = "http://www.exp.ie/"; $entry->{FETCH} = "http:\/\/www.exp.ie\/query_new.asp\?IsProvince=1\&MatchPerc=40". "\&Ranking=\&Roles=\&Recruiter=Both\&Category=3\&Location=0". "\&referrer=local\&KEYWORDS=$keyword\&I7.x=0\&I7.y=0"; $entry->{NUM_JOBS} = 0; push @{ $sites->{"www.exp.ie"}->{ENTRIES}}, $entry; $entry = {}; $entry->{PARSE} = $jobserve; $entry->{URL} = "http://www.jobserve.co.uk/"; my $tempKy = "$keyword+and+ireland"; my $vz = "\?jobType=\*\&d=7\&page=1\&q=$tempKy\&x=25\&y=9\&order=Rank"; $entry->{FETCH}="http:\/\/www.jobserve.co.uk\/searchresults.aspx$vz"; $entry->{NUM_JOBS} = 0; push @{ $sites->{"www.jobserve.co.uk"}->{ENTRIES}}, $entry; my $rcIvars="\?JobType=ACTIVE,%20ACTIVE\&County=None\&Keyword=$keyword\&B12x=\&B12y=\&myDate=2days"; $entry = {}; $entry->{PARSE} = $rcIreland; $entry->{URL} = "http://recruitIreland.ie/"; $entry->{FETCH}="http:\/\/www.recruitireland.com\/jobsearch.asp$rcIvars"; $entry->{NUM_JOBS} = 0; push @{ $sites->{"www.RecruitIreland.ie"}->{ENTRIES}}, $entry; 1; } sub getHeader() { my $ret; $ret .= < Money makin'
*** Update *** A new version of this job search site is available here. This version offers improved searching, and also RSS feeds.







END if($keyword) { my $safeKeyword = $englishKeyword; $safeKeyword =~ s#<#<#g; $safeKeyword =~ s#>#>#g; $safeKeyword =~ s#['"]##g; $ret .= <
Keyword:   
Searching for $safeKeyword jobs.





END } else { $ret .= "
"; } return $ret; } sub getFooter() { my $ret; if($keyword) { $ret .= <


Validate HTML
END } else { $ret .= <

Validate HTML END } return $ret; } sub convertToHtml() { my $ret; my $encURL =""; if(!$keyword) { return $ret; } $ret .= < END $ret .= ""; foreach my $k (keys %{$jobs}) { my $numJobs = $sites->{$k}->{NUM_JOBS}; $ret .= < $k - [$numJobs Jobs] END } $ret .= "<\/tr>"; foreach my $k (keys %{$jobs}) { $ret .= ""; my @t = (@{ $jobs->{$k}->{TITLES}}); my @l = (@{ $jobs->{$k}->{LINKS}}); for(my $i=0;$i<$#t;$i++) { $link = $l[$i]; $title = $t[$i]; $ret .= ""; $ret .= $title; $ret .= "
\n"; } $ret .= "<\/td>"; } $ret .= "<\/tr><\/table>"; return $ret; } sub ProcessSites() { foreach my $k (keys %{$sites}) { #print "Processing site: \"". $k . "\" - "; foreach my $ent (@{ $sites->{$k}->{ENTRIES}}) { my $currentParse = $ent->{PARSE}; my $append = $ent->{URL}; my $currentSite = $ent->{FETCH}; my $ua = LWP::UserAgent->new; $ua->proxy(['http', 'ftp'], $proxy); my $res = $ua->request(GET $currentSite); my $jobCount = 0; if ($res->is_success) { $data = $res->content; # print "Data: \"$data\"\n"; while ($data =~ /$currentParse/igs) { $jobCount++; $link = $1; $title = $2; if($k =~ /RecruitIreland/) { my $tt = $title; $title = $link; $link = $append .$tt; $link =~ s/<.*?>|<.*//g; } else { $title = $2; $link = $append . $1; $title =~ s/<.*?>|<.*//g; } if($title !~ /more.../) { #print "."; push @{$jobs->{$k}->{TITLES}}, $title; push @{$jobs->{$k}->{LINKS}}, $link; } } $sites->{$k}->{NUM_JOBS} = $jobCount; } #else #{ #print "FAILURE!\n"; #print "ON - \"$currentSite\"\n"; #} #print "
"; } } 1; } use CGI qw/:standard/; my $link = "http://www.redbrick.dcu.ie/~shimoda/jobsearch/index.py"; if($englishKeyword) { $link .= "?keyword=$englishKeyword"; } print redirect($link); # print header; # print "\n" . getHeader(); # if(!$englishKeyword) # { # print "\n" . convertToHtml(); # print "\n".getFooter(); # exit; # } # setupSites(); # ProcessSites(); # print "\n" . convertToHtml(); # print "\n".getFooter(); 1;