| 1 | |||
| 2 | package WWW::Scraper::apartments; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use vars qw($VERSION @ISA); | ||
| 6 | @ISA = qw(WWW::Scraper); | ||
| 7 | $VERSION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/); | ||
| 8 | use WWW::Scraper::Response; | ||
| 9 | |||
| 10 | use WWW::Scraper(qw(1.48 trimLFs)); | ||
| 11 | |||
| 12 | # SAMPLE | ||
| 13 | # http://www.apartments.com/search/oasis.dll?mfcisapicommand=quicksearch&QSearchType=1&city=New%20York&state=NY&numbeds=0&minrnt=0&maxrnt=9999 | ||
| 14 | my $scraperRequest = | ||
| 15 | { | ||
| 16 | 'type' => 'QUERY' # Type of query generation is 'QUERY' | ||
| 17 | # This is the basic URL on which to build the query. | ||
| 18 | ,'url' => 'http://www.apartments.com/search/oasis.dll?mfcisapicommand=quicksearch&QSearchType=1&' | ||
| 19 | # This is the Scraper attributes => native input fields mapping | ||
| 20 | ,'nativeQuery' => 'city' | ||
| 21 | ,'nativeDefaults' => | ||
| 22 | { 'numbeds' => 0 | ||
| 23 | ,'minrnt' => 0 | ||
| 24 | ,'maxrnt' => '9999' | ||
| 25 | ,'state' => '' | ||
| 26 | } | ||
| 27 | ,'fieldTranslations' => | ||
| 28 | { | ||
| 29 | '*' => | ||
| 30 | { '*' => '*' | ||
| 31 | } | ||
| 32 | } | ||
| 33 | # Some more options for the Scraper operation. | ||
| 34 | ,'cookies' => 0 | ||
| 35 | }; | ||
| 36 | |||
| 37 | my $scraperFrame = | ||
| 38 | [ 'HTML', | ||
| 39 | [ | ||
| 40 | [ 'COUNT', '<strong>Matches: (\d+)</strong>' ] | ||
| 41 | ,[ 'NEXT', 2, \&getNextPage ] | ||
| 42 | ,[ 'TABLE', '#2', | ||
| 43 | [[ 'TABLE', '#9', | ||
| 44 | [ | ||
| 45 | [ 'TABLE' ] # "Visual Listings". | ||
| 46 | ,[ 'HIT*' ,[ | ||
| 47 | ['TABLE', [ | ||
| 48 | [ 'TR' ] # Spacers | ||
| 49 | ,[ 'TR', | ||
| 50 | [ | ||
| 51 | [ 'TD', [ | ||
| 52 | [ 'A', 'contactUrl', undef ] | ||
| 53 | ,[ 'RESIDUE', 'phoneNumber', \&trimLFs ] | ||
| 54 | ] | ||
| 55 | ] | ||
| 56 | ,[ 'TD' ] # Spacer | ||
| 57 | ,[ 'TD', [ | ||
| 58 | [ 'A', 'locationUrl', 'location' ] | ||
| 59 | ,[ 'TAG', 'STRONG', 'address', \&trimLFs ] | ||
| 60 | ,[ 'A', 'moreInfoUrl', undef] | ||
| 61 | ,[ 'RESIDUE', 'descripition', \&trimLFs ] | ||
| 62 | ] | ||
| 63 | ] | ||
| 64 | ,['TD', 'city', \&trimLFs] | ||
| 65 | ,['TD', 'price', \&trimLFs] | ||
| 66 | ] | ||
| 67 | ] | ||
| 68 | ,['TR'] # This row has some sort of "amenities" coding. | ||
| 69 | ] | ||
| 70 | ] | ||
| 71 | ] | ||
| 72 | ] | ||
| 73 | ] | ||
| 74 | ] | ||
| 75 | ] | ||
| 76 | ] | ||
| 77 | ] | ||
| 78 | ]; | ||
| 79 | |||
| 80 | |||
| 81 | sub testParameters { | ||
| 82 | # went flippo - I'll fix this later.. | ||
| 83 | return { | ||
| 84 | 'SKIP' => 'apartments.pm still has known bugs in it.' | ||
| 85 | ,'testNativeQuery' => 'New York' | ||
| 86 | ,'testNativeOptions' => { 'state' => 'NY' } | ||
| 87 | }; | ||
| 88 | } | ||
| 89 | |||
| 90 | # Access methods for the structural declarations of this Scraper engine. | ||
| 91 | sub scraperRequest { $scraperRequest } | ||
| 92 | sub scraperFrame { $_[0]->SUPER::scraperFrame($scraperFrame); } | ||
| 93 | sub scraperDetail{ undef } | ||
| 94 | |||
| 95 | |||
| 96 | # www.apartment.com sets its NEXT button in a submit, with various labels. | ||
| 97 | # e.g. | ||
| 98 | # <input type="button" | ||
| 99 | # onclick="javascript:document.location= | ||
| 100 | # '/search/oasis.dll?page=Results&resultpos=11&QSearchType=1&minrent=0&maxrent=9999&allsizes=1&allbaths=1&month=0&status=4&state=NY&city=NEW+YORK&prvpg=7'" | ||
| 101 | # value="Last 7 >>"> | ||
| 102 | sub getNextPage { | ||
| 103 | my ($self, $hit, $dat) = @_; | ||
| 104 | return undef unless | ||
| 105 | $dat =~ m-value="Modify Search Criteria".*onclick="javascript:document\.location='(/search/oasis\.dll\?page=Results[^']*?)'[^>]*?>>">-s; | ||
| 106 | my $nxt = $1; | ||
| 107 | my $url = URI::URL->new($1, $self->{'_base_url'}); | ||
| 108 | $url = $url->abs; | ||
| 109 | return $url; | ||
| 110 | } | ||
| 111 | |||
| 112 | 1; | ||
| 113 | |||
| 114 | =pod | ||
| 115 | |||
| 116 | =head1 NAME | ||
| 117 | |||
| 118 | WWW::Scraper::apartments - Scrapes www.apartments.com | ||
| 119 | |||
| 120 | |||
| 121 | =head1 SYNOPSIS | ||
| 122 | |||
| 123 | require WWW::Scraper; | ||
| 124 | $search = new WWW::Scraper('apartments'); | ||
| 125 | |||
| 126 | |||
| 127 | =head1 DESCRIPTION | ||
| 128 | |||
| 129 | This class is an apartments specialization of WWW::Search. | ||
| 130 | It handles making and interpreting apartments searches | ||
| 131 | F<http://www.apartments.com>. | ||
| 132 | |||
| 133 | |||
| 134 | =head1 OPTIONS | ||
| 135 | |||
| 136 | To do. | ||
| 137 | |||
| 138 | =head1 OPTIONS | ||
| 139 | |||
| 140 | To do | ||
| 141 | |||
| 142 | =head1 AUTHOR | ||
| 143 | |||
| 144 | C<WWW::apartments> is written and maintained | ||
| 145 | by Glenn Wood, http://search.cpan.org/search?mode=author&query=GLENNWOOD. | ||
| 146 | |||
| 147 | The best place to obtain C<WWW::apartments> | ||
| 148 | is from Glenn's releases on CPAN. Because www.apartments.com | ||
| 149 | sometimes changes its format in between his releases, | ||
| 150 | sometimes more up-to-date versions can be found at | ||
| 151 | F<http://alumni.caltech.edu/~glenwood/SOFTWARE/index.html>. | ||
| 152 | |||
| 153 | =head1 COPYRIGHT | ||
| 154 | |||
| 155 | Copyright (c) 2001 Glenn Wood | ||
| 156 | All rights reserved. | ||
| 157 | |||
| 158 | This program is free software; you can redistribute it and/or | ||
| 159 | modify it under the same terms as Perl itself. | ||
| 160 | |||
| 161 | =cut | ||
| 162 | |||
| 163 |