| 1 | |||
| 2 | package WWW::Scraper::CraigsList; | ||
| 3 | |||
| 4 | ##################################################################### | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use vars qw($VERSION @ISA); | ||
| 8 | @ISA = qw(WWW::Scraper); | ||
| 9 | use WWW::Scraper(qw(3.02 generic_option addURL trimTags)); | ||
| 10 | use WWW::Scraper::FieldTranslation; | ||
| 11 | |||
| 12 | $VERSION = sprintf("%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/); | ||
| 13 | |||
| 14 | # Craigs List differs from other search engines in a few ways. | ||
| 15 | # One of them is the results page is not tablulated, or data lined. | ||
| 16 | # It returns each job listing on a single line. | ||
| 17 | # This line can be parsed with a single regular expression, which is what we do. | ||
| 18 | # | ||
| 19 | # SAMPLE : | ||
| 20 | # | ||
| 21 | # <br>Apr 24 - <a href=/sfo/eng/959347.html>Senior Software Engineer</a> (San Francisco)<font size=-1> (internet engineering jobs)</font></br> | ||
| 22 | # | ||
| 23 | # | ||
| 24 | # private | ||
| 25 | |||
| 26 | # NOTE: sometimes the response may read: | ||
| 27 | # | ||
| 28 | # craigslist: online community | ||
| 29 | # craigslist | ||
| 30 | # online community | ||
| 31 | # The requested function is offline for maintenance. | ||
| 32 | # Please try again a little later. | ||
| 33 | # | ||
| 34 | # NEW: by 2002.09.27 | ||
| 35 | # Jobs - web-dev | ||
| 36 | # http://www.craigslist.org/cgi-bin/search?areaID=1&subAreaID=0&catAbbreviation=eng&cat=14&group=J&type_search=&query=Perl&new_cat=14 | ||
| 37 | # Jobs - software/QA/DBA/etc jobs | ||
| 38 | # http://www.craigslist.org/cgi-bin/search?areaID=1&subAreaID=0&catAbbreviation=sof&cat=21&group=J&type_search=&query=Quality&new_cat=21 return { | ||
| 39 | # Car stuff | ||
| 40 | # http://www.craigslist.org/cgi-bin/search?areaID=1&subAreaID=0&catAbbreviation=car&cat=6&group=S&type_search=&query=honda+accord&new_cat=6&maxAsk=11000 | ||
| 41 | # http://www.craigslist.org/cgi-bin/search?areaID=1&subAreaID=0&catAbbreviation=car&cat=6&group=S&type_search=&query=Honda&new_cat=6&maxAsk= | ||
| 42 | my $scraperRequest = | ||
| 43 | { | ||
| 44 | 'type' => 'POST' # Type of query generation is 'POST' | ||
| 45 | # This is the basic URL on which to build the query. | ||
| 46 | ,'url' => 'http://www.craigslist.org/cgi-bin/search?' | ||
| 47 | # This is the Scraper attributes => native input fields mapping | ||
| 48 | ,'nativeQuery' => 'query' | ||
| 49 | ,'nativeDefaults' => | ||
| 50 | { 'areaID' => '1' | ||
| 51 | ,'subAreaID' => '0' | ||
| 52 | ,'group' => 'S' | ||
| 53 | ,'cat' => 'all' | ||
| 54 | ,'new_cat' => '6' | ||
| 55 | ,'catAbbreviation' => 'car' | ||
| 56 | ,'group' => 'J' | ||
| 57 | ,'type_search' => '' | ||
| 58 | ,'min_ask' => '' # catAbbreviation='car' | ||
| 59 | ,'max_ask' => '' # catAbbreviation='car' | ||
| 60 | ,'query' => '' | ||
| 61 | } | ||
| 62 | # ,'defaultRequestClass' => 'Job' | ||
| 63 | ,'fieldTranslations' => | ||
| 64 | { '*' => | ||
| 65 | { '*' => '*' | ||
| 66 | ,'skills' => 'query' | ||
| 67 | # ,'payrate' => \&translatePayrate | ||
| 68 | ,'locations' => new WWW::Scraper::FieldTranslation('CraigsList', 'Job', 'locations') | ||
| 69 | } | ||
| 70 | } | ||
| 71 | # Some more options for the Scraper operation. | ||
| 72 | ,'cookies' => 0 | ||
| 73 | }; | ||
| 74 | |||
| 75 | my $scraperFrame = | ||
| 76 | [ 'HTML', | ||
| 77 | [ | ||
| 78 | [ 'NEXT', 'Next ' ] | ||
| 79 | ,[ 'BODY', '</FORM>', '' , | ||
| 80 | [ | ||
| 81 | [ 'COUNT', 'Found: (\d+)'] | ||
| 82 | ,[ 'HIT*' , | ||
| 83 | [ | ||
| 84 | # NEW: by 2002.09.27 | ||
| 85 | #<p> May-18 <a href=/sfc/mcy/11439880.html>=====>>2001 Honda XR 650L - $3500</a> (vallejo) <<<i><a href=/mcy/>cycles</a></i> | ||
| 86 | #<p> Sep-26 <a href=/sfo/pen/eng/5905447.html>Plugged In Enterprises Web Producer </a> (East Palo Alto) | ||
| 87 | [ 'REGEX', '<p>\s*( )*(\w*?-\d+)[^<]*<a\s+href=([^>]+)>(.*?)</a>([^<]*)', | ||
| 88 | undef, 'date', 'url', 'title', 'location' | ||
| 89 | ] | ||
| 90 | ] | ||
| 91 | ] | ||
| 92 | ] | ||
| 93 | ] | ||
| 94 | ] | ||
| 95 | ]; | ||
| 96 | |||
| 97 | |||
| 98 | sub testParameters { | ||
| 99 | # 'POST' style scraperFrames can't be tested cause of a bug in WWW::Search(2.2[56]) ! | ||
| 100 | my $isNotTestable = WWW::Scraper::isGlennWood()?0:0; | ||
| 101 | # http://www.craigslist.org/cgi-bin/search?areaID=1&subAreaID=0&catAbbreviation=sof&cat=21&group=J&type_search=&query=Quality&new_cat=21 return { | ||
| 102 | return { | ||
| 103 | 'SKIP' => $isNotTestable | ||
| 104 | ,'testNativeQuery' => 'Honda' | ||
| 105 | ,'expectedOnePage' => 50 | ||
| 106 | ,'expectedMultiPage' => 100 | ||
| 107 | ,'expectedBogusPage' => 0 | ||
| 108 | # http://www.craigslist.org/cgi-bin/search?areaID=1&subAreaID=0&catAbbreviation=car&group=S&type_search=&query=Honda&cat=6&minAsk=min&maxAsk=max | ||
| 109 | ,'testNativeOptions' => { 'areaID' => '1' | ||
| 110 | ,'subAreaID' => '0' | ||
| 111 | ,'group' => 'S' | ||
| 112 | ,'cat' => 'all' | ||
| 113 | ,'new_cat' => '6' | ||
| 114 | ,'catAbbreviation' => 'car' | ||
| 115 | ,'group' => 'S' | ||
| 116 | ,'type_search' => '' | ||
| 117 | ,'min_ask' => 'min' | ||
| 118 | ,'max_ask' => 'max' | ||
| 119 | } | ||
| 120 | ,'usesPOST' => 1 | ||
| 121 | }; | ||
| 122 | } | ||
| 123 | |||
| 124 | sub init { | ||
| 125 | my ($self) = @_; | ||
| 126 | $self->searchEngineHome('http://www.CraigsList.org'); | ||
| 127 | $self->searchEngineLogo('<font size=5><b>craigslist</b></font>'); | ||
| 128 | return $self; | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | # Access methods for the structural declarations of this Scraper engine. | ||
| 133 | sub scraperRequest { $scraperRequest } | ||
| 134 | sub scraperFrame { $_[0]->SUPER::scraperFrame($scraperFrame); } | ||
| 135 | sub scraperDetail{ undef } | ||
| 136 | |||
| 137 | 1; | ||
| 138 | __END__ |