| 1 |
# Jobserve.pm |
| 2 |
# Written by Andy Pritchard. |
| 3 |
# $Id: Jobserve.pm,v 1.02 2003-09-25 16:13:30 ninja $ |
| 4 |
|
| 5 |
package WWW::Search::Jobserve; |
| 6 |
|
| 7 |
@ISA = qw( WWW::Search ); |
| 8 |
|
| 9 |
use WWW::Search qw( generic_option strip_tags ); |
| 10 |
use WWW::Search::Result; |
| 11 |
|
| 12 |
$VERSION = '1.02'; |
| 13 |
$MAINTAINER = 'Andy Pritchard <[email protected]>'; |
| 14 |
|
| 15 |
# private |
| 16 |
sub native_setup_search |
| 17 |
{ |
| 18 |
my ($self, $native_query, $rhOptsArg) = @_; |
| 19 |
|
| 20 |
# Set some private variables: |
| 21 |
$self->{_debug} ||= $rhOptsArg->{'search_debug'}; |
| 22 |
$self->{_debug} = 2 if ($rhOptsArg->{'search_parse_debug'}); |
| 23 |
$self->{_debug} ||= 0; |
| 24 |
|
| 25 |
|
| 26 |
my $DEFAULT_HITS_PER_PAGE = 50; |
| 27 |
$self->{'_hits_per_page'} = $DEFAULT_HITS_PER_PAGE; |
| 28 |
|
| 29 |
my $sjob_category = $rhOptsArg->{'job_category'}; |
| 30 |
my $sjobserve_site = $rhOptsArg->{'jobserve_site'}; |
| 31 |
my $sjob_type = $rhOptsArg->{'job_type'}; |
| 32 |
my $sjob_lookahead = $rhOptsArg->{'job_lookahead'}; |
| 33 |
my $sjob_order = $rhOptsArg->{'job_order'}; |
| 34 |
$sjobserve_site ||= 'uk'; # Default to English site |
| 35 |
$sjob_type ||= '*'; # Default to all |
| 36 |
$sjob_lookahead ||= '5'; # Default to 5 Days |
| 37 |
$sjob_order ||= 'Rank';# Default to Rank (Best Match) |
| 38 |
|
| 39 |
my %Country_Params = ( uk => 'jobserve.com/jobserve/', |
| 40 |
au => 'job-serve.com.au/jobserve/', |
| 41 |
) ; |
| 42 |
|
| 43 |
$self->user_agent('non-robot'); |
| 44 |
|
| 45 |
$self->{'_next_to_retrieve'} = 0; |
| 46 |
$self->{'_num_hits'} = 0; |
| 47 |
$self->{'_base_url'} = "http://www.$sjob_category.$Country_Params{$sjobserve_site}"; |
| 48 |
|
| 49 |
if (!defined($self->{_options})) |
| 50 |
{ |
| 51 |
$self->{_options} = { |
| 52 |
'search_url' => $self->{'_base_url'} . 'searchresults.asp', |
| 53 |
'jobType' => $sjob_type, # Job Type (*|C|P) == (Any|Contract|Permanent) |
| 54 |
'd' => $sjob_lookahead, # No of days to look ahead |
| 55 |
'order' => $sjob_order,# Sort order (Rank|DateTime) == (Best Match|Latest Job) |
| 56 |
'q' => $native_query, # The escaped query |
| 57 |
}; |
| 58 |
} # if |
| 59 |
if (defined($rhOptsArg)) |
| 60 |
{ |
| 61 |
# Copy in new options. |
| 62 |
foreach my $key (keys %$rhOptsArg) |
| 63 |
{ |
| 64 |
#print STDERR " + inspecting option $key..."; |
| 65 |
if (WWW::Search::generic_option($key)) |
| 66 |
{ |
| 67 |
print STDERR "promote & delete\n"; |
| 68 |
$self->{$key} = $rhOptsArg->{$key} if defined($rhOptsArg->{$key}); |
| 69 |
delete $rhOptsArg->{$key}; |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
#print STDERR "copy\n"; |
| 74 |
$self->{_options}->{$key} = $rhOptsArg->{$key} if defined($rhOptsArg->{$key}); |
| 75 |
} |
| 76 |
} # foreach |
| 77 |
} # if |
| 78 |
|
| 79 |
die " - Must specify a job category to search...\n" unless (defined($self->{_options}->{'job_category'})); |
| 80 |
# Finally, figure out the url. |
| 81 |
$self->{_next_url} = $self->{_options}->{'search_url'} .'?'. $self->hash_to_cgi_string($self->{_options}); |
| 82 |
} # native_setup_search |
| 83 |
|
| 84 |
sub preprocess_results_page |
| 85 |
{ |
| 86 |
my $self = shift; |
| 87 |
my $sPage = shift; |
| 88 |
print STDERR " + RawHTML ===>$sPage<=== RawHTML\n" if 2 < $self->{_debug}; |
| 89 |
return $sPage; |
| 90 |
} # preprocess_results_page |
| 91 |
|
| 92 |
# private |
| 93 |
sub parse_tree |
| 94 |
{ |
| 95 |
my $self = shift; |
| 96 |
my $tree = shift; |
| 97 |
|
| 98 |
# A pattern to match HTML whitespace: |
| 99 |
my $W = q{[\ \t\r\n\240]}; |
| 100 |
my $hits_found = 0; |
| 101 |
if (2 < $self->{_debug}) { |
| 102 |
print STDERR "=========================== HTML::Tree Dump START ============================\n"; |
| 103 |
print STDERR $tree->as_HTML(); |
| 104 |
print STDERR "============================ HTML::Tree Dump END =============================\n"; |
| 105 |
} |
| 106 |
# The hit count is in a FONT tag: |
| 107 |
my @aoFONT = $tree->look_down('_tag', 'font'); |
| 108 |
my @aoTABLE = $tree->look_down('_tag', 'table'); |
| 109 |
|
| 110 |
FONT: |
| 111 |
foreach my $oFONT (@aoFONT) |
| 112 |
{ |
| 113 |
print STDERR " + try FONT ===", $oFONT->as_text, "===\n" if 1 < $self->{_debug}; |
| 114 |
if ($oFONT->as_text =~ m!of (\d+) Matching Jobs!) |
| 115 |
{ |
| 116 |
$self->approximate_result_count($1); |
| 117 |
last FONT; |
| 118 |
} # if |
| 119 |
} # foreach |
| 120 |
TABLE: |
| 121 |
foreach my $oTABLE (@aoTABLE) # Go <table> -> <td> -> <font1> -> <font2> -> <font3> -> <font4> |
| 122 |
{ |
| 123 |
print STDERR " + try TABLE ===", $oTABLE->as_HTML, "===\n" if 1 < $self->{_debug}; |
| 124 |
my @aoFONT = $oTABLE->look_down('_tag', 'font'); |
| 125 |
my $oFONT = shift(@aoFONT); |
| 126 |
next TABLE unless ref $oFONT; |
| 127 |
print STDERR " + try TABLE->FONT ===", $oFONT->as_text, "===\n" if 1 < $self->{_debug}; |
| 128 |
# First A tag contains the url & title: |
| 129 |
my @aoA = $oFONT->look_down('_tag', 'a'); |
| 130 |
my $oA = shift(@aoA); |
| 131 |
next TABLE unless ref $oA; |
| 132 |
next TABLE if (($oA->as_HTML) =~ m!class="ToolBar"!ig); |
| 133 |
print STDERR " + try TABLE->FONT->A ===", $oA->as_HTML, "===\n" if 1 < $self->{_debug}; |
| 134 |
# Occasionally they have these atsco links in there, this skips over in this case. |
| 135 |
if (($oA->as_HTML) !~ m!\?jobid\=!ig) { |
| 136 |
$oA = shift(@aoA); |
| 137 |
print STDERR " + Re-try TABLE->FONT->A ===", $oA->as_HTML, "===\n" if 1 < $self->{_debug}; |
| 138 |
} |
| 139 |
# Jobserve only gives us a path relative to the _base_url |
| 140 |
my $sURL = $self->{'_base_url'} . $oA->attr('href'); |
| 141 |
print STDERR " + GOT URL:$sURL:\n" if 1 < $self->{_debug}; |
| 142 |
my $sTitle = $oA->as_text; |
| 143 |
print STDERR " + GOT Title:$sTitle:\n" if 1 < $self->{_debug}; |
| 144 |
# Now go down another font |
| 145 |
my $oFONT2 = shift(@aoFONT); |
| 146 |
# And another |
| 147 |
my $oFONT3 = shift(@aoFONT); |
| 148 |
print STDERR " + try TABLE->FONT3 ===", $oFONT3->as_text, "===\n" if 1 < $self->{_debug}; |
| 149 |
my $sDesc = $oFONT3->as_text; |
| 150 |
# And yet another |
| 151 |
my $oFONT4 = shift(@aoFONT); |
| 152 |
$oFONT4 = shift(@aoFONT) if (($oFONT4->as_text) =~ m!more\.\.\.!); |
| 153 |
print STDERR " + try TABLE->FONT4 ===", $oFONT4->as_text, "===\n" if 1 < $self->{_debug}; |
| 154 |
$sDesc .= $oFONT4->as_text; |
| 155 |
|
| 156 |
my $hit = new WWW::Search::Result; |
| 157 |
$hit->add_url($sURL); |
| 158 |
$hit->title($sTitle); |
| 159 |
$hit->description($sDesc); |
| 160 |
#$hit->change_date($sDate); |
| 161 |
push(@{$self->{cache}}, $hit); |
| 162 |
$self->{'_num_hits'}++; |
| 163 |
$hits_found++; |
| 164 |
# Delete this HTML element so that future searches go faster! |
| 165 |
$oTABLE->detach; |
| 166 |
$oTABLE->delete; |
| 167 |
} # foreach TABLE |
| 168 |
|
| 169 |
# Look for a Next Page link: |
| 170 |
my @aoA = $tree->look_down('_tag', 'a'); |
| 171 |
TRY_NEXT: |
| 172 |
foreach my $oA (reverse @aoA) |
| 173 |
{ |
| 174 |
next TRY_NEXT unless ref $oA; |
| 175 |
print STDERR " + try NEXT A ===", $oA->as_HTML, "===\n" if 1 < $self->{_debug}; |
| 176 |
my $href = $oA->attr('href'); |
| 177 |
next TRY_NEXT unless $href; |
| 178 |
last TRY_NEXT if $href =~ m!JobDetail!; |
| 179 |
if ($oA->as_text =~ m!Next Page!i) |
| 180 |
{ |
| 181 |
$self->{_next_url} = $self->absurl(undef, $href); |
| 182 |
print STDERR " + got NEXT A ===", $self->{_next_url}, "===\n" if 1 < $self->{_debug}; |
| 183 |
last TRY_NEXT; |
| 184 |
} # if |
| 185 |
} # foreach |
| 186 |
|
| 187 |
# All done with this page. |
| 188 |
$tree->delete; |
| 189 |
return $hits_found; |
| 190 |
} # parse_tree |
| 191 |
|
| 192 |
1; |
| 193 |
|
| 194 |
__END__ |
| 195 |
|
| 196 |
##################################################################### |
| 197 |
|
| 198 |
=head1 NAME |
| 199 |
|
| 200 |
WWW::Search::Jobserve - backend for searching www.jobserve.com |
| 201 |
|
| 202 |
=head1 SYNOPSIS |
| 203 |
|
| 204 |
use WWW::Search; |
| 205 |
my $oSearch = new WWW::Search('Jobserve'); |
| 206 |
my $sQuery = WWW::Search::escape_query("(Fast Food Operative) and PERL"); |
| 207 |
$oSearch->native_query($sQuery, { job_category => 'it' }); |
| 208 |
while (my $oResult = $oSearch->next_result()) |
| 209 |
{ |
| 210 |
print $oResult->url, "\n"; |
| 211 |
print $oResult->title, "\n"; |
| 212 |
print $oResult->description, "\n"; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
=head1 DESCRIPTION |
| 217 |
|
| 218 |
This class is a Jobserve specialisation of WWW::Search. |
| 219 |
It handles making, retrieving and interpreting Jobserve searches |
| 220 |
F<http://www.jobserve.com>. |
| 221 |
|
| 222 |
This class exports no public interface; all interaction should |
| 223 |
be done through L<WWW::Search> objects. |
| 224 |
|
| 225 |
=head1 NOTES |
| 226 |
|
| 227 |
This class can be used to query both the UK and Australian Jobserve sites, see below. |
| 228 |
|
| 229 |
The search will terminate unless C<job_category> is set in the native_query options. |
| 230 |
|
| 231 |
The results are ordered Best Match first |
| 232 |
(unless 'job_order' => 'DateTime' is specified). |
| 233 |
|
| 234 |
=head1 OPTIONS |
| 235 |
|
| 236 |
Parameters Available: |
| 237 |
|
| 238 |
F<job_category> |
| 239 |
F<job_type> |
| 240 |
F<job_lookahead> |
| 241 |
F<job_order> |
| 242 |
F<jobserve_site> |
| 243 |
|
| •244 |
=over |
| 245 |
|
| 246 |
=item Job Category |
| 247 |
|
| 248 |
Job Categories must be specified by setting C<job_category> |
| 249 |
in the native_query options: |
| 250 |
|
| 251 |
$oSearch->native_query($sQuery, { job_category => 'it' }); |
| 252 |
|
| 253 |
The value of this is simply the prefix you see jobserve insert |
| 254 |
into the url once you've clicked beyond the front page. E.g. |
| 255 |
|
| 256 |
http://www.it.jobserve.com { job_category => 'it' } |
| 257 |
http://www.engineering.jobserve.com { job_category => 'engineering' } |
| 258 |
|
| 259 |
etc. |
| 260 |
|
| 261 |
=item Job Type |
| 262 |
|
| 263 |
Job Types are (Any|Contract|Permanent). |
| 264 |
To specifically search for one contract type, |
| 265 |
set 'job_type' => (*|C|P) to the query options: |
| 266 |
|
| 267 |
$oSearch->native_query($sQuery, { job_type => 'C', job_category => 'it' } ); |
| 268 |
|
| 269 |
The search defaults to C<All> |
| 270 |
|
| 271 |
=item Days Ahead |
| 272 |
|
| 273 |
Choices of how many days to look ahead are (5|4|3|2|1|0). |
| 274 |
To specifically search for x working days ahead, |
| 275 |
set 'job_lookahead' => (5|4|3|2|1|0) to the query options: |
| 276 |
|
| 277 |
$oSearch->native_query($sQuery, { job_lookahead => '2', job_category => 'it' } ); |
| 278 |
|
| 279 |
The search defaults to C<5> |
| 280 |
|
| 281 |
=item Result Order |
| 282 |
|
| 283 |
Choices of how to order results are (Best Match|Latest Job). |
| 284 |
To alter the result order, |
| 285 |
set 'job_order' => (Rank|DateTime) to the query options: |
| 286 |
|
| 287 |
$oSearch->native_query($sQuery, { job_order => 'DateTime', job_category => 'it' } ); |
| 288 |
|
| 289 |
The search defaults to C<Best Match>. |
| 290 |
|
| 291 |
=item Different Jobserve Sites |
| 292 |
|
| 293 |
There are currently two Jobserve websites supported by this module |
| 294 |
namely United Kingdom and Australia. |
| 295 |
The search will default to the UK site unless the parameter, |
| 296 |
'jobserve_site' => (uk|au) is set in the query options: |
| 297 |
|
| 298 |
$oSearch->native_query($sQuery, { jobserve_site => 'au', job_category => 'it' } ); |
| 299 |
|
| 300 |
The search defaults to C<uk> |
| 301 |
|
| •302 |
=item Invocation |
| 303 |
|
| 304 |
Invoke all parameters like so: |
| 305 |
|
| 306 |
$oSearch->native_query($sQuery, { job_category => 'it', |
| 307 |
job_type => 'C', |
| 308 |
job_lookahead => '2', |
| 309 |
job_order => 'DateTime', |
| 310 |
jobserve_site => 'au', } ); |
| 311 |
|
| 312 |
=back |
| 313 |
|
| 314 |
=head1 SEE ALSO |
| 315 |
|
| 316 |
To make new back-ends, see L<WWW::Search>. |
| 317 |
|
| 318 |
=head1 BUGS |
| 319 |
|
| 320 |
Doubt it. Please tell me if you find any! Better still have a go at fixing them. |
| 321 |
|
| 322 |
=head1 AUTHOR |
| 323 |
|
| 324 |
C<WWW::Search::Jobserve> was written by Andy Pritchard |
| 325 |
([email protected]). |
| 326 |
|
| 327 |
C<WWW::Search::Jobserve> is maintained by Andy Pritchard |
| 328 |
|
| 329 |
=head1 LEGALESE |
| 330 |
|
| 331 |
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
| 332 |
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 333 |
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 334 |
|
| 335 |
=head1 VERSION HISTORY |
| 336 |
|
| 337 |
=head2 1.02 |
| 338 |
|
| 339 |
Altered parse_tree for cases where another href link is inserted before |
| 340 |
the job title and link |
| 341 |
|
| 342 |
=head2 1.01 |
| 343 |
|
| 344 |
Altered POD and added a README |
| 345 |
|
| 346 |
=head2 1.00 |
| 347 |
|
| 348 |
Released to the public. |
| 349 |
|
| 350 |
=cut |
| 351 |
|
| •352 |
##################################################################### |