| WWW-Search-Jobs documentation | Contained in the WWW-Search-Jobs distribution. |
WWW::Search::Monster - class for searching Monster
use WWW::Search;
my $oSearch = new WWW::Search('Monster');
my $sQuery = WWW::Search::escape_query("perl and (perl or perl)");
$oSearch->native_query($sQuery,
{'st' => 'CA',
'tm' => '14d'});
while (my $res = $oSearch->next_result()) {
print $res->company . "\t" . $res->title . "\t" . $res->change_date
. "\t" . $res->location . "\t" . $res->url . "\n";
}
This class is a Monster specialization of WWW::Search. It handles making and interpreting Monster searches at http://www.monster.com. Monster supports Boolean logic with "and"s "or"s. See http://jobsearch.monster.com/jobsearch_tips.asp for a full description of the query language.
The returned WWW::SearchResult objects contain url, title, company, location and change_date fields.
The following search options can be activated by sending a hash as the second argument to native_query().
use {'lid' => $location_id}
Only jobs in $location_id. To find out what $location_id you need, please look at the source of http://jobsearch.monster.com. Note that $location_id does not mean the area telephone code. The default is no location restriction.
Use {'fn' => $cat_id} to select one or more job categories you want. For multiple selection use a '+' sign, e.g. {'fn' => '1+2'}. Possible categories are:
WWW::Search::Monster is written and maintained by Alexander Tkatchev
(Alexander.Tkatchev@cern.ch).
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
| WWW-Search-Jobs documentation | Contained in the WWW-Search-Jobs distribution. |
# Monster.pm # Author: Alexander Tkatchev # e-mail: Alexander.Tkatchev@cern.ch # # WWW::Search back-end for Monster # http://jobsearch.monster.com/jobsearch.asp # Maint: # 4/20/01 # Wayne Rogers # fixed a problem that skewed results on column to the right. # Monster now uses only a location ID (lid) vice city, state. # 2006-02-25 Brian Sammon # Parsing code update and pod updates.
##################################################################### package WWW::Search::Monster; use strict; use warnings; use Carp (); use HTML::TokeParser; use WWW::Search qw(generic_option); use base 'WWW::Search'; use WWW::SearchResult; our $VERSION = do { my @r = (q$Revision: 2.5 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; sub native_setup_search { my($self, $native_query, $native_options_ref) = @_; $self->{agent_e_mail} = 'alexander.tkatchev@cern.ch'; $self->user_agent('non-robot'); if (!defined($self->{_options})) { $self->{'search_base_url'} = 'http://jobsearch.monster.com'; $self->{_options} = { 'search_url' => $self->{'search_base_url'} . '/jobsearch.asp', 'q' => $native_query }; } # if my $options_ref = $self->{_options}; if (defined($native_options_ref)) { # Copy in new options. foreach (keys %$native_options_ref) { $options_ref->{$_} = $native_options_ref->{$_}; } # foreach } # if # Process the options. my($options) = ''; foreach (sort keys %$options_ref) { # printf STDERR "option: $_ is " . $options_ref->{$_} . "\n"; next if (generic_option($_)); $options_ref->{$_} =~ s/\+/\,/g if($_ eq 'st'); $options_ref->{$_} =~ s/\+/\&$_=/g unless($_ eq 'q'); $options .= $_ . '=' . $options_ref->{$_} . '&'; } # foreach # Finally figure out the url. $self->{_next_url} = $self->{_options}{'search_url'} .'?'. $options;; $self->{_debug} = $options_ref->{'search_debug'}; } # native_setup_search # private sub native_retrieve_some { my ($self) = @_; my $debug = $self->{'_debug'}; print STDERR " * Monster::native_retrieve_some()\n" if($debug); # fast exit if already done return 0 if (!defined($self->{_next_url})); # get some print STDERR " * sending request (",$self->{_next_url},")\n" if($debug); my($response) = $self->http_request('GET', $self->{_next_url}); $self->{'_next_url'} = undef; if (!$response->is_success) { print STDERR $response->error_as_HTML; return 0; }; print STDERR " * got response\n" if($debug); if($response->content =~ m/No jobs matched the query/) { print STDERR "No jobs matched the query\n"; return 0; } my ($token,$tag); my $content = $response->content(); my $p = new HTML::TokeParser(\$content); $content =~ s|<b>||ig; $content =~ s|</b>||ig; $content =~ s/ / /ig; $content =~ m/Jobs (\d+) to (\d+) of (\d+)/; my $nrows = $2 - $1 + 1; $self->approximate_hit_count($3); # Determine _next_url my ($nexturl) = ($content =~ /<a[^>]*href="([^"]*)[^>]*>Next page >></ ); $self->{'_next_url'} = $self->{search_base_url} . $nexturl; my($hits_found) = 0; my($hit) = (); $p = new HTML::TokeParser(\$content); #skim the content until we reach the header row of the main table while($p->get_tag("td")) { my $data = $p->get_trimmed_text("/td"); last if($data eq 'Location' || $data eq 'Company' || $data eq 'Modified'); # 'Modified' is not used anymore (Jan06) } for(my $i = 0; $i< $nrows; $i++) { $tag = $p->get_tag("tr"); #Jump to beginning of next row $tag = $p->get_tag("td"); my $date = $p->get_trimmed_text("/td"); $tag = $p->get_tag("a"); my $url = $self->{'search_base_url'} . $tag->[1]{href}; my $title = $p->get_trimmed_text("/a"); $tag = $p->get_tag("td"); my $company = $p->get_trimmed_text("/td"); $tag = $p->get_tag("a"); my $location = $p->get_trimmed_text("/a"); $hit = new WWW::SearchResult; $hit->url($url); $hit->company($company); $hit->change_date($date); $hit->title($title); $hit->location($location); push(@{$self->{cache}}, $hit); $hits_found++; } # return 0; return $hits_found; } # native_retrieve_some 1; __END__