WWW/Scraper/Lycos.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 71 CC 2 SCAR 10.6
CC
2
Cov
0%
testParameters
6.0
removeDescriptionTags
2.0
scraperRequest
2.0
CRAP 2.9
1  
2 package WWW::Scraper::Lycos;
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.0 $ =~ /(\d+)\.(\d+)/);
12  
13 use Carp ();
14 use WWW::Scraper(qw(3.03 generic_option addURL trimTags trimLFs removeScriptsInHTML));
15  
16 use strict;
17  
18 # Example query - (old) http://search.lycos.com/main/default.asp?lpv=1&loc=searchhp&query=Perl
19 # (new) http://search.lycos.com/default.asp?lpv=1&loc=searchhp&tab=web&query=turntable
20 my $scraperRequest =
21 {
22 # This engine is driven from it's <form> page
23 'type' => 'QUERY'
24
25 # This is the basic URL on which to get the form to build the query.
26 ,'url' => 'http://search.lycos.com/default.asp?'
27  
28 # specify defaults, by native field names
29 ,'nativeQuery' => 'query'
30 ,'nativeDefaults' => { 'lpv' => '1'
31 ,'loc' => 'searchhp'
32 ,'tab' => 'web'
33 }
34
35 # specify translations from canonical fields to native fields
36 ,'fieldTranslations' =>
37 {
38 '*' =>
39 { 'skills' => 'query'
40 ,'*' => '*'
41 }
42 }
43 # Miscellaneous options for the Scraper operation.
44 ,'cookies' => 0
45 };
46  
47 my $scraperFrame =
48 [ 'HTML',
49 [
50 [ 'NEXT', '<b>Next</b>' ] #<b>Next</b>
51  
52 ,[ 'COUNT', 'Showing\s+Results\s+<b>[\d-]+</b>\s+of\s+([\d,]+)']
53 ,[ 'BODY', '<!-- IL -->', '<!-- /IL -->',
54 [
55 [ 'TR' ]
56 ,[ 'HIT*', # sponsored links
57 [
58 [ 'TR',
59 [
60 #[ 'TD', 'number' ]
61 [ 'A', 'url', 'title' ]
62 ,[ 'FONT', 'sponsored' ]
63 ,[ 'BR', 'description' ]
64 ]
65 ]
66 ,[ 'TR' ]
67 ]
68 ]
69 ,[ 'HIT*', # web results
70 [
71 [ 'BODY', '<!-- IS -->', '<!-- /IS -->',
72 [
73 [ 'REGEX', '<!-- REL (\d+%)-->', 'relevance' ]
74 ,[ 'A', 'url', 'title' ]
75 ,[ 'BR', 'description' ]
76 ]
77 ]
78 ]
79 ]
80 ]
81 ]
82 ]
83 ];
84  
85  
86 # Lycos has <DESCRIPTION> opening tags, but no closing ones.
87 # That seems pretty handy, but gets in the way of TidyXML.
88 sub removeDescriptionTags {
89 my ($self, $hit, $xml) = @_;
90 $$xml =~ s{- <DESCRIPTION>(.*?)</\s?DESCRIPTION>}{$1}gsi;
91 $$xml =~ s{- <DESCRIPTION/>}{}gsi;
92 return $xml;
93 }
94  
95 sub testParameters {
96 my ($self) = @_;
97  
98 if ( ref $self ) {
99 $self->{'isTesting'} = 1;
100 }
101
102 return {
103 'TODO' => ''
104 ,'testNativeQuery' => 'turntable'
105 ,'expectedOnePage' => 9
106 ,'expectedMultiPage' => 20
107 ,'expectedBogusPage' => 1
108 };
109 }
110  
111 # Access methods for the structural declarations of this Scraper engine.
112 sub scraperRequest { $scraperRequest }
113 sub scraperFrame { return $scraperFrame; $_[0]->SUPER::scraperFrame($scraperFrame); }
114  
115 1;
116  
117  
118 __END__