WWW/Scraper/Dogpile.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 78 CC 3 SCAR 11.7
CC
3
Cov
0%
findNextForm
6.0
import
6.0
cleanUpLeadingTrailingBRs
2.0
CRAP 3.2
1  
2 package WWW::Scraper::Dogpile;
3  
4  
5 #####################################################################
6  
7 require Exporter;
8 @EXPORT = qw();
9 @EXPORT_OK = qw(trimTags);
10 @ISA = qw(WWW::Scraper Exporter);
11 $VERSION = sprintf("%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/);
12  
13 use Carp ();
14 use WWW::Scraper(qw(2.27 generic_option));
15  
16 use strict;
17  
18 # Example query - http://search.lycos.com/main/default.asp?lpv=1&loc=searchhp&query=Perl
19 my $scraperRequest =
20 {
21 # This engine is driven from it's <form> page
22 'type' => 'QUERY'
23
24 # This is the basic URL on which to get the form to build the query.
25 ,'url' => 'http://search.dogpile.com/texis/search?'
26  
27 # specify defaults, by native field names
28 ,'nativeQuery' => 'q'
29 ,'nativeDefaults' => { 'Fetch.x' => '1'
30 ,'Fetch.y' => '1'
31 ,'geo' => 'no'
32 ,'fs' => 'The Web'
33 }
34
35 # specify translations from canonical fields to native fields
36 ,'fieldTranslations' =>
37 {
38 '*' =>
39 { 'skills' => 'q'
40 ,'*' => '*'
41 }
42 }
43 # Miscellaneous options for the Scraper operation.
44 ,'cookies' => 0
45 # Some search engines don't connect every time - retry Dogpile this many times.
46 ,'retry' => 1
47 };
48  
49 my $scraperFrame =
50 [ 'HTML',
51 [
52 [ 'NEXT', \&findNextForm ],
53 [ 'HIT*',
54 [
55 #<font face="verdana, sans-serif" size="2">3. <a href="http://clickit.go2net.com/search?site=srch&cid=239134&area=srch.comm.overture&shape=textlink&cp=info.dogpl&rawto=http://www9.overture.com/d/sr/?xargs=02u3hs9yoaj1UKsTDChBjFX5spp%2FCTf0O0mIZQpChwe6VrSYKFGqbBUxe3QVP1vLuO1u%2By%2F%2BrzwffmnZHlqXIRERDIJSVEo%2BQKgSkuND9EaQXW6q7qVVfbZ7G%2B8e2jB2a0LBZtL01lzCaDRoyJWeahwcZA6Mji%2FDLv4brtMhri4nxMzwVJnUVAg7iuTtjsfPwUdK5185CSMVTgdQEaiTQN9bDlXpxcb0M9Jg%3D%3D">Retro
56 #Radios, Turntables and Phones</a></font><br>
57 #<font face="verdana, sans-serif" size="2">View our selection of brand name turn
58 #tables at discounted prices. Shop all the decorative and fun radios, record
59 #players and more. Purchase securely online. http://www.fun-radios.com<br>
60 #</font> <br>
61 [ 'REGEX', '<font face="verdana, sans-serif" size="2">(\d+)\.\s+.*?href="([^"]*)"[^>]*>(.*?)</a>.*?<br>(.*?)<br>', 'number', 'url', 'title', 'description' ]
62 # ,[ 'A', 'go2netUrl', 'title' ]
63 # ,[ 'SPAN', 'url' ]
64 # ,[ 'RESIDUE', 'description', \&cleanUpLeadingTrailingBRs ]
65 ]
66 ]
67 ]
68 ];
69
70 sub cleanUpLeadingTrailingBRs {
71 my ($self, $hit, $dat) = @_;
72 $dat =~ s{^\s*<br>}{}si;
73 $dat =~ s{<br><br>\s*$}{}si;
74 return $dat;
75 }
76  
77  
78 # #######################################################################################
79 # Get the Next URL from a <form> on the page.
80 # Sometimes there's just a NEXT form, sometimes there's a PREV form and a NEXT form . . .
81 use HTML::Form;
82 sub findNextForm {
83 my ($self, $hit, $dat) = @_;
84
85 if ( $dat =~ m{(<FORM\s+action.*?">.*?next 10 engines.*?</FORM>)}si ) {
86 my $form = HTML::Form->parse($1, $self->{'_base_url'});
87 my $req = $form->make_request;
88 return $req->uri;
89 }
90 return '';
91 }
92  
93  
94 sub testParameters {
95 my ($self) = @_;
96  
97 return {
98 'SKIP' => &WWW::Scraper::TidyXML::isNotTestable('Dogpile')
99 ,'testNativeQuery' => 'turntable'
100 ,'expectedOnePage' => 9
101 ,'expectedMultiPage' => 60
102 ,'expectedBogusPage' => 1
103 };
104 }
105  
106 sub import
107 {
108 my $package = shift;
109  
110 my @exports = grep { "HASH" ne ref($_) } @_;
111 my @options = grep { "HASH" eq ref($_) } @_;
112  
113 foreach (@options)
114 {
115 if ( $_->{'scraperBaseURL'} ) {
116 $scraperRequest->{'url'} = $_->{'scraperBaseURL'};
117 }
118 }
119  
120 @_ = ($package, @exports);
121 goto &Exporter::import;
122 }
123  
124 # Access methods for the structural declarations of this Scraper engine.
125 sub scraperRequest { $scraperRequest }
126 sub scraperFrame { $_[0]->SUPER::scraperFrame($scraperFrame); }
127  
128 1;
129  
130  
131 __END__