| 1 | use strict; | ||
| 2 | package WWW::Scraper::ScraperDiscovery; | ||
| 3 | |||
| 4 | ##################################################################### | ||
| 5 | |||
| 6 | use base qw(WWW::Scraper Exporter); | ||
| 7 | # This is an appropriate VERSION calculation to use for CVS revision numbering. | ||
| 8 | use vars qw($VERSION); | ||
| 9 | $VERSION = sprintf("%d.%02d", q$Revision: 1.0 $ =~ /(\d+).(\d+)/); | ||
| 10 | |||
| 11 | use WWW::Scraper(qw(3.00 generic_option trimLFs trimTags removeScriptsInHTML)); | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | |||
| 15 | my $scraperRequest = | ||
| 16 | { | ||
| 17 | # This engine's method is QUERY | ||
| 18 | 'type' => 'QUERY' | ||
| 19 | |||
| 20 | # This is the basic URL on which to get the form to build the query. | ||
| 21 | ,'url' => 'http://google.com' | ||
| 22 | |||
| 23 | # specify defaults, by native field names | ||
| 24 | ,'nativeQuery' => undef | ||
| 25 | ,'nativeDefaults' => {'rootUrl' => '1' } | ||
| 26 | |||
| 27 | # specify translations from canonical fields to native fields | ||
| 28 | ,'defaultRequestClass' => undef | ||
| 29 | ,'fieldTranslations' => | ||
| 30 | { | ||
| 31 | '*' => | ||
| 32 | { | ||
| 33 | '*' => '*' | ||
| 34 | } | ||
| 35 | } | ||
| 36 | # Miscellaneous options for the Scraper operation. | ||
| 37 | ,'cookies' => 0 | ||
| 38 | }; | ||
| 39 | |||
| 40 | sub generateQuery { | ||
| 41 | my ($self) = @_; | ||
| 42 | $scraperRequest->{'url'} = $self->{'native_query'}; | ||
| 43 | return $scraperRequest->{'url'}; | ||
| 44 | } | ||
| 45 | |||
| 46 | my $scraperFrame = | ||
| 47 | [ 'HTML', | ||
| 48 | [ | ||
| 49 | [ 'HIT*', 'ScraperDiscovery::FORM', | ||
| 50 | [ | ||
| 51 | [ 'FORM', | ||
| 52 | [ | ||
| 53 | [ 'HIT*', 'ScraperDiscovery::INPUT', | ||
| 54 | [ | ||
| 55 | [ 'INPUT' ] | ||
| 56 | ] | ||
| 57 | ] | ||
| 58 | ,[ 'HIT*', 'ScraperDiscovery::SELECT', | ||
| 59 | [ | ||
| 60 | [ 'SELECT', | ||
| 61 | [ | ||
| 62 | [ 'HIT*', 'ScraperDiscovery::OPTION', | ||
| 63 | [ | ||
| 64 | [ 'OPTION' ] | ||
| 65 | ] | ||
| 66 | ] | ||
| 67 | ] | ||
| 68 | ] | ||
| 69 | ] | ||
| 70 | ] | ||
| 71 | ] | ||
| 72 | ], | ||
| 73 | ] | ||
| 74 | ], | ||
| 75 | ] | ||
| 76 | ]; | ||
| 77 | |||
| 78 | my $scraperFrame1 = | ||
| 79 | [ 'HTML', | ||
| 80 | [ | ||
| 81 | [ 'HIT*', 'ScraperDiscovery::FORM', | ||
| 82 | [ | ||
| 83 | [ 'FORM', | ||
| 84 | [ | ||
| 85 | [ 'HIT*', 'ScraperDiscovery::INPUT', | ||
| 86 | [ | ||
| 87 | [ 'INPUT' ] | ||
| 88 | ] | ||
| 89 | ] | ||
| 90 | ,[ 'HIT*', 'ScraperDiscovery::SELECT', | ||
| 91 | [ | ||
| 92 | [ 'SELECT', | ||
| 93 | [ | ||
| 94 | [ 'HIT*', 'ScraperDiscovery::OPTION', | ||
| 95 | [ | ||
| 96 | [ 'OPTION' ] | ||
| 97 | ] | ||
| 98 | ] | ||
| 99 | ] | ||
| 100 | ] | ||
| 101 | ] | ||
| 102 | ] | ||
| 103 | ] | ||
| 104 | ], | ||
| 105 | ] | ||
| 106 | ], | ||
| 107 | ] | ||
| 108 | ]; | ||
| 109 | |||
| 110 | my $scraperFrame2 = | ||
| 111 | [ 'HTML', | ||
| 112 | [ | ||
| 113 | [ 'HIT*', 'ScraperDiscovery::BODY', | ||
| 114 | [ | ||
| 115 | [ 'BODY', | ||
| 116 | [ | ||
| 117 | [ 'HIT*', 'ScraperDiscovery::NEXT', | ||
| 118 | [ 'DISCOVERNEXT' ] | ||
| 119 | ] | ||
| 120 | ,[ 'MACRO', 'TABLELOOP', | ||
| 121 | [ | ||
| 122 | [ 'HIT*', 'ScraperDiscovery::TABLE', | ||
| 123 | [ | ||
| 124 | [ 'TABLE' ] | ||
| 125 | ,[ 'HIT*', 'ScraperDiscovery::TR', | ||
| 126 | [ | ||
| 127 | [ 'TR', | ||
| 128 | [ | ||
| 129 | [ 'HIT*', 'ScraperDiscovery::TD', | ||
| 130 | [ | ||
| 131 | [ 'A', 'url', 'urlCaption' ] | ||
| 132 | ,[ 'A', 'url', 'urlCaption' ] | ||
| 133 | ,[ 'A', 'url', 'urlCaption' ] | ||
| 134 | ,[ 'A', 'url', 'urlCaption' ] | ||
| 135 | ,[ 'TD' ] | ||
| 136 | ,[ 'MACROX', 'TABLELOOP' ] | ||
| 137 | ] | ||
| 138 | ] | ||
| 139 | ] | ||
| 140 | ] | ||
| 141 | ] | ||
| 142 | ] | ||
| 143 | ] | ||
| 144 | ] | ||
| 145 | ] | ||
| 146 | ] | ||
| 147 | ] | ||
| 148 | ], | ||
| 149 | ] | ||
| 150 | ], | ||
| 151 | ] | ||
| 152 | ]; | ||
| 153 | |||
| 154 | |||
| 155 | sub init { | ||
| 156 | my ($self, $subclass, $native_query, $native_options) = @_; | ||
| 157 | |||
| 158 | if ( $native_options->{'SCRAPERREQUEST'} ) { | ||
| 159 | $self->SetScraperRequest($native_options->{'SCRAPERREQUEST'}); | ||
| 160 | } else { | ||
| 161 | $self->SetScraperRequest($scraperRequest); | ||
| 162 | } | ||
| 163 | |||
| 164 | if ( $native_options->{'PHASE'} ) { | ||
| 165 | my $phase = $native_options->{'PHASE'}; | ||
| 166 | $self->SetScraperFrame($scraperFrame1) if $phase == 1; | ||
| 167 | $self->SetScraperFrame($scraperFrame2) if $phase == 2; | ||
| 168 | } else { | ||
| 169 | $self->SetScraperFrame($scraperFrame1); | ||
| 170 | } | ||
| 171 | |||
| 172 | $self->SetScraperDetail(undef); | ||
| 173 | return $self->SUPER::init($subclass, $native_query); | ||
| 174 | } | ||
| 175 | |||
| 176 | 1; | ||
| 177 | |||
| 178 | __END__ |