| 1 | ### Yandex.pm | ||||||||||||||||||||||||||||||||||
| 2 | ### | ||||||||||||||||||||||||||||||||||
| 3 | ### Copyright (C) 2004 by Artur Penttinen | ||||||||||||||||||||||||||||||||||
| 4 | ### Last modified: <Tuesday, 27-Jun-2006 14:56 EEST> | ||||||||||||||||||||||||||||||||||
| 5 | ### | ||||||||||||||||||||||||||||||||||
| 6 | ### $Id:$ | ||||||||||||||||||||||||||||||||||
| 7 | ### | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | package WWW::Search::Yandex; | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use base "WWW::Search"; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use WWW::SearchResult; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use HTML::TreeBuilder; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Encode qw( from_to decode ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Encode::Byte; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 1 | our $VERSION = qw$Revision: 0.05 $[1]; | |||||||||||||||||||||||||||||||||
| 24 | 1 | our $MAINTAINER = 'Artur Penttinen <artur+perl@niif.spb.su>'; | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 1 | our $iMustPause = 1; | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub native_setup_search ($$$) { | ||||||||||||||||||||||||||||||||
|
Subroutine
native_setup_search: called CC=9 SCAR=28.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 29 | 1 | my ( $self,$query,$opt ) = @_; | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | printf STDERR " + native_setup_search('%s','%s')\n",$query,$opt || "" | ||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | if ($self->{'_debug'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$opt || ''
MC/DC0%0/1
$opt || ''
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 1 | $self->{'native_query'} = uri_escape_utf8($query); | |||||||||||||||||||||||||||||||||
| 35 | 1 | $self->{'_next_to_retrieve'} = 0; | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 1 | $self->{'agent_name'} = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)'; | |||||||||||||||||||||||||||||||||
| 38 | 1 | $self->{'agent_e_mail'} = "nobody\@niif.spb.su"; | |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | $self->{'search_base_url'} ||= "http://www.yandex.ru"; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"search_base_url"} ||= "http://www.yandex.ru"
MC/DC0%0/1
$self->{"search_base_url"} ||= "http://www.yandex.ru"
$self->{"search_base_url"}
Truth table50%1/2
A
A= $self->{"search_base_url"}
| |||||||||||||||||||||||||||||||||||
| 41 | 1 | $self->{'search_base_path'} = "/yandsearch"; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 1 | $self->cookie_jar (new HTTP::Cookies); | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | unless (defined ($self->{'_options'})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | # We do not clobber the existing _options hash, if there is one; | ||||||||||||||||||||||||||||||||||
| 47 | # e.g. if gui_search () was already called on this object | ||||||||||||||||||||||||||||||||||
| 48 | 1 | $self->{'_options'} = { 'text' => $self->{'native_query'}, | |||||||||||||||||||||||||||||||||
| 49 | 'nl' => "0", | ||||||||||||||||||||||||||||||||||
| 50 | 'stype' => "www", | ||||||||||||||||||||||||||||||||||
| 51 | # 'n' => $self->{_hits_per_page}, | ||||||||||||||||||||||||||||||||||
| 52 | # 'b' => $self->{_next_to_retrieve}-1 | ||||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 1 | my $opts = $self->{'_options'}; | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | 1 | foreach my $key (keys %$opt) { | |||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (WWW::Search::generic_option ($key)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->{$key} = $opts->{$key} if (exists ($opts->{$key})); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | delete $opts->{$key}; | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $opts->{$key} = $opt->{$key} if (exists ($opt->{$key})); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | $self->{'_next_url'} = $self->{'search_base_url'} . | ||||||||||||||||||||||||||||||||||
| 69 | 1 | $self->{'search_base_path'} .'?'. | |||||||||||||||||||||||||||||||||
| 70 | $self->hash_to_cgi_string ($opts); | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 1 | return; | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub parse_tree ($$) { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_tree: called CC=36 SCAR=65.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 76 | 1 | my ( $self,$oTree ) = @_; | |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | printf STDERR " + %s got a tree $oTree\n",__PACKAGE__ | ||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | # Every time we get a page from yandex.ru, we have to pause before | ||||||||||||||||||||||||||||||||||
| 82 | # fetching another. | ||||||||||||||||||||||||||||||||||
| 83 | 1 | $iMustPause++; | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 1 | my $hits_found = 0; | |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | # Only try to parse the hit count if we haven't done so already: | ||||||||||||||||||||||||||||||||||
| 88 | printf STDERR " + start, approx_h_c is ==%d==\n", | ||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | $self->approximate_hit_count() if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | if ($self->approximate_hit_count () < 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | # Sometimes the hit count is inside a <DIV> tag: | ||||||||||||||||||||||||||||||||||
| 93 | 1 | my @aoDIV = $oTree->look_down('_tag' => "div", | |||||||||||||||||||||||||||||||||
| 94 | 'class' => "ygbody"); | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | DIV_TAG: | ||||||||||||||||||||||||||||||||||
| 97 | 1 | foreach my $oDIV (@aoDIV) { | |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | next unless (ref $oDIV); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | printf STDERR " + try DIV ==%s", | ||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $oDIV->as_HTML () if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 0 | my $s = $oDIV->as_text (); | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | print STDERR " + TEXT ==$s==\n" if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 0 | my $iCount = $self->_string_has_count ($s); | |||||||||||||||||||||||||||||||||
| 107 | 0 | $iCount =~ tr#,\.##d; | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($iCount >= 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->approximate_result_count ($iCount); | |||||||||||||||||||||||||||||||||
| 111 | 0 | last DIV_TAG; | |||||||||||||||||||||||||||||||||
| 112 | } # if | ||||||||||||||||||||||||||||||||||
| 113 | } # foreach DIV_TAG | ||||||||||||||||||||||||||||||||||
| 114 | } # if | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | if ($self->approximate_hit_count () < 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | # Sometimes the hit count is inside a <small> tag: | ||||||||||||||||||||||||||||||||||
| 118 | 1 | my @aoDIV = $oTree->look_down ('_tag' => "small"); | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | SMALL_TAG: | ||||||||||||||||||||||||||||||||||
| 121 | 1 | foreach my $oDIV (@aoDIV) { | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | next unless (ref $oDIV); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | print STDERR " + try SMALL ==",$oDIV->as_HTML () | ||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | 0 | my $s = $oDIV->as_text (); | |||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | print STDERR " + TEXT ==$s==\n" if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | 0 | my $iCount = $self->_string_has_count ($s); | |||||||||||||||||||||||||||||||||
| 131 | 0 | $iCount =~ tr#,\.##d; | |||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($iCount >= 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | 0 | $self->approximate_result_count ($iCount); | |||||||||||||||||||||||||||||||||
| 135 | 0 | last SMALL_TAG; | |||||||||||||||||||||||||||||||||
| 136 | } # if | ||||||||||||||||||||||||||||||||||
| 137 | } # foreach DIV_TAG | ||||||||||||||||||||||||||||||||||
| 138 | } # if | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | printf STDERR " + found approx_h_c is ==%s==\n", | ||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | $self->approximate_hit_count () if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 1 | my @aoLI = $oTree->look_down ('_tag' => "li"); | |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | LI_TAG: | ||||||||||||||||||||||||||||||||||
| 146 | 1 | foreach my $oLI (@aoLI) { | |||||||||||||||||||||||||||||||||
| 147 | # Sanity check: | ||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | next LI_TAG unless (ref ($oLI)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 0 | my @aoA = $oLI->look_down ('_tag' => "a"); | |||||||||||||||||||||||||||||||||
| 151 | 0 | my $oA = shift @aoA; | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | next LI_TAG unless (ref($oA)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $sTitle = $oA->as_text || ""; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$oA->as_text || ''
MC/DC0%0/1
$oA->as_text || ''
$oA->as_text
Truth table0%0/2
A
A= $oA->as_text
| |||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $sURL = $oA->attr ("href") || ""; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$oA->attr('href') || ''
MC/DC0%0/1
$oA->attr('href') || ''
$oA->attr('href')
Truth table0%0/2
A
A= $oA->attr('href')
| |||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | next LI_TAG unless ($sURL ne ""); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | print STDERR " + raw URL is ==$sURL==\n" | ||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | # Throw out Yahoo category links that pop up on a failed query: | ||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | next LI_TAG if ($sURL =~ m#/search3/empty/catlink/#); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | # Throw out Yahoo suggested further-search: | ||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | next LI_TAG if ($sURL =~ m#search.yahoo.com/search#); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 0 | unshift @aoA,$oA; | |||||||||||||||||||||||||||||||||
| 167 | # Strip off the yahoo.com redirect part of the URL: | ||||||||||||||||||||||||||||||||||
| 168 | 0 | $sURL =~ s#\A.*?\*-##; | |||||||||||||||||||||||||||||||||
| 169 | print STDERR " + cooked URL is ==$sURL==\n" | ||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | # Delete the useless human-readable restatement of the URL (first | ||||||||||||||||||||||||||||||||||
| 173 | # <EM> tag we come across): | ||||||||||||||||||||||||||||||||||
| 174 | 0 | my $oEM = $oLI->look_down ('_tag' => "em"); | |||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if (ref $oEM) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 176 | 0 | $oEM->detach (); | |||||||||||||||||||||||||||||||||
| 177 | 0 | $oEM->delete (); | |||||||||||||||||||||||||||||||||
| 178 | } # if | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | A_TAG: | ||||||||||||||||||||||||||||||||||
| 181 | 0 | foreach my $oA (@aoA) { | |||||||||||||||||||||||||||||||||
| 182 | 0 | $oA->detach (); | |||||||||||||||||||||||||||||||||
| 183 | 0 | $oA->delete (); | |||||||||||||||||||||||||||||||||
| 184 | } # foreach A_TAG | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | 0 | my $sDesc = $oLI->as_text (); | |||||||||||||||||||||||||||||||||
| 187 | print STDERR " + raw sDesc is ==$sDesc==\n" | ||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | # Grab stuff off the end of the description: | ||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $sSize = $1 if ($sDesc =~ s#\s+(-\s+)+(\d+k?)(\s+-)+\s+\Z##); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $sSize ||= ""; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sSize ||= ""
MC/DC0%0/1
$sSize ||= ""
$sSize
Truth table0%0/2
A
A= $sSize
| |||||||||||||||||||||||||||||||||||
| 193 | print STDERR " + cooked sDesc is ==$sDesc==\n" | ||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | 0 | my $hit = new WWW::SearchResult; | |||||||||||||||||||||||||||||||||
| 197 | 0 | $hit->add_url ($sURL); | |||||||||||||||||||||||||||||||||
| 198 | 0 | $sTitle = $self->strip ($sTitle); | |||||||||||||||||||||||||||||||||
| 199 | 0 | $sDesc = $self->strip ($sDesc); | |||||||||||||||||||||||||||||||||
| 200 | 0 | $hit->title ($sTitle); | |||||||||||||||||||||||||||||||||
| 201 | 0 | $hit->description ($sDesc); | |||||||||||||||||||||||||||||||||
| 202 | 0 | $hit->size ($sSize); | |||||||||||||||||||||||||||||||||
| 203 | 0 | push @{ $self->{'cache'} },$hit; | |||||||||||||||||||||||||||||||||
| 204 | 0 | $hits_found++; | |||||||||||||||||||||||||||||||||
| 205 | } # foreach LI_TAG | ||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | # Now try to find the "next page" link: | ||||||||||||||||||||||||||||||||||
| 208 | 1 | my @aoA = $oTree->look_down('_tag' => "a"); | |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | NEXT_A: | ||||||||||||||||||||||||||||||||||
| 211 | 1 | foreach my $oA (reverse @aoA) { | |||||||||||||||||||||||||||||||||
| 212 | 5 | ▶ | next NEXT_A unless (ref ($oA)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 213 | 5 | my $sAhtml = $oA->as_HTML (); | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | printf STDERR " + next A ==%s==\n", $sAhtml | ||||||||||||||||||||||||||||||||||
| 216 | 5 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | 5 | ▶ | if ($self->_a_is_next_link ($oA)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 219 | 0 | my $sURL = $oA->attr ('href'); | |||||||||||||||||||||||||||||||||
| 220 | # Delete Yahoo-redirect portion of URL: | ||||||||||||||||||||||||||||||||||
| 221 | 0 | $sURL =~ s#\A.+?\*?-?(?=http)##; | |||||||||||||||||||||||||||||||||
| 222 | 0 | $self->{'_next_url'} = $self->absurl ($self->{'_prev_url'},$sURL); | |||||||||||||||||||||||||||||||||
| 223 | 0 | last NEXT_A; | |||||||||||||||||||||||||||||||||
| 224 | } # if | ||||||||||||||||||||||||||||||||||
| 225 | } # foreach NEXT_A | ||||||||||||||||||||||||||||||||||
| 226 | 1 | return $hits_found; | |||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | 1 | ▶ | sub native_retrieve_some ($) { | ||||||||||||||||||||||||||||||||
|
Subroutine
native_retrieve_some: called CC=15 SCAR=32.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 230 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | printf STDERR " + %s::native_retrieve_some ()\n",__PACKAGE__ | ||||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | if ($self->{'_debug'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||
| 235 | # Fast exit if already done: | ||||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | return unless (defined $self->{'_next_url'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | # If this is not the first page of results, sleep so as to not | ||||||||||||||||||||||||||||||||||
| 239 | # overload the server: | ||||||||||||||||||||||||||||||||||
| 240 | 1 | ▶ | $self->user_agent_delay () if ($self->{'_next_to_retrieve'} > 1 || | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_next_to_retrieve"} > 1 or $self->need_to_delay
MC/DC0%0/2
$self->{"_next_to_retrieve"} > 1 or $self->need_to_delay
$self->{"_next_to_retrieve"} > 1
$self->need_to_delay
Truth table33%1/3
A or B
A= $self->{"_next_to_retrieve"} > 1B= $self->need_to_delay
| |||||||||||||||||||||||||||||||||||
| 241 | $self->need_to_delay ()); | ||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | # Get one page of results: | ||||||||||||||||||||||||||||||||||
| 244 | printf STDERR " + submitting URL (%s)\n",$self->{'_next_url'} | ||||||||||||||||||||||||||||||||||
| 245 | 1 | ▶ | if ($self->{'_debug'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||
| 247 | my $response = $self->http_request ($self->http_method (), | ||||||||||||||||||||||||||||||||||
| 248 | 1 | $self->{'_next_url'}); | |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | printf STDERR " + got response\n%s\n", $response | ||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | 1 | $self->{'_prev_url'} = $self->{'_next_url'}; | |||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||
| 255 | # Assume there are no more results, unless we find out otherwise | ||||||||||||||||||||||||||||||||||
| 256 | # when we parse the html: | ||||||||||||||||||||||||||||||||||
| 257 | 1 | $self->{'_next_url'} = undef; | |||||||||||||||||||||||||||||||||
| 258 | 1 | $self->{'response'} = $response; | |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | printf STDERR " --- HTTP response is:%s\n", $response->as_string () | ||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | if ($self->{'_debug'} >= 5); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | unless ($response->is_success ()) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 264 | printf STDERR " --- HTTP request failed, response is:\n%s", | ||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | $response->as_string if ($self->{'_debug'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 266 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 267 | } # if | ||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | # Pre-process the output: | ||||||||||||||||||||||||||||||||||
| 270 | 1 | my $sPage = $self->preprocess_results_page ($response->content ()); | |||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | # Parse the output: | ||||||||||||||||||||||||||||||||||
| 273 | 1 | my $tree; | |||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | if (ref ($self->{'_treebuilder'})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 275 | print STDERR " + using existing _treebuilder\n" | ||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ($self->{_debug} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 277 | # Assume that the backend has installed their own TreeBuilder | ||||||||||||||||||||||||||||||||||
| 278 | 0 | $tree = $self->{'_treebuilder'}; | |||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||
| 280 | else { | ||||||||||||||||||||||||||||||||||
| 281 | 1 | ▶ | print STDERR " + creating new _treebuilder\n" if ($self->{_debug}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 282 | 1 | $tree = new HTML::TreeBuilder (); # use all default options | |||||||||||||||||||||||||||||||||
| 283 | 1 | $tree->store_comments ("yes"); | |||||||||||||||||||||||||||||||||
| 284 | 1 | $self->{'_treebuilder'} = $tree; | |||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | # If a reset() method becomes available in HTML::TreeBuilder, | ||||||||||||||||||||||||||||||||||
| 288 | # we can change this: | ||||||||||||||||||||||||||||||||||
| 289 | 1 | $tree->www_search_reset (); | |||||||||||||||||||||||||||||||||
| 290 | # print STDERR " + parsing content, tree is ", Dumper(\$tree) | ||||||||||||||||||||||||||||||||||
| 291 | # if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | 1 | $tree->parse ($sPage); | |||||||||||||||||||||||||||||||||
| 294 | 1 | ▶ | print STDERR " + done parsing content.\n" if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 295 | 1 | $tree->eof (); | |||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | 1 | ▶ | print STDERR " + calling parse_tree...\n" if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 298 | 1 | return $self->parse_tree ($tree); | |||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | sub http_request ($$$) { | ||||||||||||||||||||||||||||||||
|
Subroutine
http_request: called CC=32 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 302 | 1 | my ( $self,$method,$url ) = @_; | |||||||||||||||||||||||||||||||||
| 303 | 1 | my $response; | |||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | 1 | ▶ | if ($self->{'_debug'} >= 50) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 306 | 0 | eval q{ use LWP::Debug qw(+) }; | |||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | if (defined ($self->{'search_from_file'})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 310 | 0 | $response = $self->_http_request_from_file ($url); | |||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||||
| 313 | # fetch it | ||||||||||||||||||||||||||||||||||
| 314 | 1 | my $ua = $self->user_agent ($self->{'agent_name'}); | |||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | unless (exists ($self->{'_prev_url'})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 317 | # Get cookie from first page | ||||||||||||||||||||||||||||||||||
| 318 | 1 | my $request = new HTTP::Request ($method,"http://www.yandex.ru"); | |||||||||||||||||||||||||||||||||
| 319 | 1 | $self->{'_cookie_jar'}->add_cookie_header ($request); | |||||||||||||||||||||||||||||||||
| 320 | 1 | my $resp = $ua->request($request); | |||||||||||||||||||||||||||||||||
| 321 | 1 | $self->{'_http_referer'} = "http://www.yandex.ru"; | |||||||||||||||||||||||||||||||||
| 322 | 1 | my $cookie = $resp->header ("Set-Cookie"); | |||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | if (defined ($cookie) && $cookie =~ m#yandexuid=(\S+);#) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $cookie and $cookie =~ /yandexuid=(\S+);/
MC/DC0%0/2
defined $cookie and $cookie =~ /yandexuid=(\S+);/
defined $cookie
$cookie =~ /yandexuid=(\S+);/
Truth table33%1/3
A and B
A= defined $cookieB= $cookie =~ /yandexuid=(\S+);/
| |||||||||||||||||||||||||||||||||||
| 324 | 1 | $self->{'_cookie_yandexuid'} = $1; | |||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | printf STDERR "+ got cookie: %s\n", | ||||||||||||||||||||||||||||||||||
| 328 | $self->{'_cookie_yandexuid'} || "(none)" | ||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | if ($self->{'_debug'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'_cookie_yandexuid'} || '(none)'
MC/DC0%0/1
$self->{'_cookie_yandexuid'} || '(none)'
$self->{'_cookie_yandexuid'}
Truth table0%0/2
A
A= $self->{'_cookie_yandexuid'}
| |||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | 1 | sleep (2); # we will enter request :) | |||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | 1 | my $request = new HTTP::Request ($method,$url); | |||||||||||||||||||||||||||||||||
| 335 | 1 | $request->header ("Content-Type","text/html; charset=windows-1251"); | |||||||||||||||||||||||||||||||||
| 336 | $request->header ("Cookie",sprintf "yandexuid=%s", | ||||||||||||||||||||||||||||||||||
| 337 | $self->{'_cookie_yandexuid'}) | ||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | if (exists $self->{'_cookie_yandexuid'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | $request->proxy_authorization_basic ($self->http_proxy_user, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 341 | $self->http_proxy_pwd) | ||||||||||||||||||||||||||||||||||
| 342 | if ($self->is_http_proxy_auth_data ()); | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | $self->{'_cookie_jar'}->add_cookie_header ($request) | ||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | if (exists ($self->{'_cookie_jar'})); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | 1 | ▶ | if ($self->{'_http_referer'} && $self->{'_http_referer'} ne "") { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_http_referer"} and $self->{"_http_referer"} ne ""
MC/DC0%0/2
$self->{"_http_referer"} and $self->{"_http_referer"} ne ""
$self->{"_http_referer"}
$self->{"_http_referer"} ne ""
Truth table33%1/3
A and B
A= $self->{"_http_referer"}B= $self->{"_http_referer"} ne ""
| |||||||||||||||||||||||||||||||||||
| 348 | # my $s = uri_escape ($self->{'_http_referer'}); | ||||||||||||||||||||||||||||||||||
| 349 | 1 | my $s = $self->{'_http_referer'}; | |||||||||||||||||||||||||||||||||
| 350 | printf STDERR " + referer(%s), ref(s) = %s\n",$s,ref($s) | ||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | if ($self->{'_debug'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 352 | 1 | ▶ | $s = $s->as_string () if (ref ($s) =~ m#URI#); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 353 | 1 | $request->referer ($s); | |||||||||||||||||||||||||||||||||
| 354 | } # if referer | ||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||
| 356 | printf STDERR " + original HTTP::Request is:\n%s\n", | ||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | $request->as_string () if ($self->{'_debug'} >= 3); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||
| 359 | TRY_GET: | ||||||||||||||||||||||||||||||||||
| 360 | 1 | while (1) { | |||||||||||||||||||||||||||||||||
| 361 | 1 | $response = $ua->request($request); | |||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||
| 363 | printf STDERR " + got HTTP::Response (code=%d):\n%s", | ||||||||||||||||||||||||||||||||||
| 364 | $response->code (),$response->headers ()->as_string () | ||||||||||||||||||||||||||||||||||
| 365 | 1 | ▶ | if ($self->{'_debug'} >= 3); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | 1 | ▶ | if (exists ($self->{'_cookie_jar'})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 368 | 1 | $self->{'_cookie_jar'}->extract_cookies ($response); | |||||||||||||||||||||||||||||||||
| 369 | $self->{'_cookie_jar'}->save () | ||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | if ($self->{'_cookie_jar_we_save'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 371 | print STDERR " + WWW::Search just extracted cookies\n" | ||||||||||||||||||||||||||||||||||
| 372 | 1 | ▶ | if ($self->{'_debug'} > 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 373 | print STDERR $self->{'_cookie_jar'}->as_string () | ||||||||||||||||||||||||||||||||||
| 374 | 1 | ▶ | if ($self->{'_debug'} > 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 375 | # print STDERR Dumper($self->{'_cookie_jar'}) if DEBUG_COOKIES; | ||||||||||||||||||||||||||||||||||
| 376 | } # if | ||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||
| 378 | 1 | ▶ | if ($self->{'search_to_file'} && $response->is_success ()) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"search_to_file"} and $response->is_success
MC/DC0%0/2
$self->{"search_to_file"} and $response->is_success
$self->{"search_to_file"}
$response->is_success
Truth table33%1/3
A and B
A= $self->{"search_to_file"}B= $response->is_success
| |||||||||||||||||||||||||||||||||||
| 379 | 0 | $self->_http_request_to_file ($url,$response); | |||||||||||||||||||||||||||||||||
| 380 | } # if | ||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | 1 | ▶ | last TRY_GET if ($response->is_success ()); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | last TRY_GET if ($response->is_error ()); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | last TRY_GET if ($response->headers ()->header ("Client-Warning") =~ m|redirect loop detected|i); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | if ($response->is_redirect () || | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->is_redirect or $response->message =~ /Object moved/i
MC/DC0%0/2
$response->is_redirect or $response->message =~ /Object moved/i
$response->is_redirect
$response->message =~ /Object moved/i
Truth table0%0/3
A or B
A= $response->is_redirectB= $response->message =~ /Object moved/i
| |||||||||||||||||||||||||||||||||||
| 387 | $response->message =~ m|Object moved|i) { | ||||||||||||||||||||||||||||||||||
| 388 | 0 | my $sURL = $response->request->uri->as_string; | |||||||||||||||||||||||||||||||||
| 389 | 0 | my $sURLredir = $response->headers->header ("Location"); | |||||||||||||||||||||||||||||||||
| 390 | # Low-level loop detection: | ||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | last TRY_GET if ($sURLredir eq $sURL); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 392 | print STDERR " + 'Object moved' from $sURL to $sURLredir\n" | ||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ($self->{'_debug'} >= 2); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 394 | # Follow the redirect: | ||||||||||||||||||||||||||||||||||
| 395 | 0 | $request = new HTTP::Request("GET", | |||||||||||||||||||||||||||||||||
| 396 | URI->new_abs($sURLredir, $sURL)); | ||||||||||||||||||||||||||||||||||
| 397 | 0 | $request->referer ($sURL); | |||||||||||||||||||||||||||||||||
| 398 | $self->{'_cookie_jar'}->add_cookie_header ($request) | ||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if (ref($self->{'_cookie_jar'})); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | print STDERR " + 'Object moved', new HTTP::Request is:\n", | ||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | $request->as_string () if ($self->{'_debug'} >= 3); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 403 | # Go back and try again | ||||||||||||||||||||||||||||||||||
| 404 | } # if | ||||||||||||||||||||||||||||||||||
| 405 | } # while infinite | ||||||||||||||||||||||||||||||||||
| 406 | } # if not from_file | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | 1 | return $response; | |||||||||||||||||||||||||||||||||
| 409 | } # http_request | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | sub strip ($$) { | ||||||||||||||||||||||||||||||||
|
Subroutine
strip: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 413 | 0 | my ( $self,$s ) = @_; | |||||||||||||||||||||||||||||||||
| 414 | 0 | $s = &WWW::Search::strip_tags ($s); | |||||||||||||||||||||||||||||||||
| 415 | 0 | $s =~ s#\A[\240\t\r\n\ ]+ ##x; | |||||||||||||||||||||||||||||||||
| 416 | 0 | $s =~ s# [\240\t\r\n\ ]+\Z##x; | |||||||||||||||||||||||||||||||||
| 417 | 0 | return $s; | |||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||
| 420 | 5 | ▶ | sub _a_is_next_link ($;$) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_a_is_next_link: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||||||||
| 421 | 5 | my ( $self,$oA ) = @_; | |||||||||||||||||||||||||||||||||
| 422 | 5 | ▶ | return 0 unless (defined ($oA)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 423 | 5 | my $t = $oA->as_text; $t =~ s#....$##; # | |||||||||||||||||||||||||||||||||
| 424 | 5 | ▶ | return ($t eq "õíåäèáüâó" || | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$t eq "\365\355\345\344\350\341\374\342\363" || $t eq "\323\314\305\304\325\300\335\301\321" || $t eq 'ÓÌÅÄÕÀÝÁÑ <span>→</span>'
$t eq "\365\355\345\344\350\341\374\342\363" or $t eq "\323\314\305\304\325\300\335\301\321"
MC/DC0%0/3
$t eq "\365\355\345\344\350\341\374\342\363" || $t eq "\323\314\305\304\325\300\335\301\321" || $t eq 'ÓÌÅÄÕÀÝÁÑ <span>→</span>'
$t eq "\365\355\345\344\350\341\374\342\363"
$t eq "\323\314\305\304\325\300\335\301\321"
$t eq 'ÓÌÅÄÕÀÝÁÑ <span>→</span>'
Truth table25%1/4
A or B || C
A= $t eq "\365\355\345\344\350\341\374\342\363"B= $t eq "\323\314\305\304\325\300\335\301\321"C= $t eq 'ÓÌÅÄÕÀÝÁÑ <span>→</span>'
| |||||||||||||||||||||||||||||||||||
| 425 | $t eq "ÓÌÅÄÕÀÝÁÑ" || | ||||||||||||||||||||||||||||||||||
| 426 | $t eq "ÓÌÅÄÕÀÝÁÑ <span>→</span>"); | ||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||
| 429 | 1 | ▶ | sub preprocess_results_page ($$) { | ||||||||||||||||||||||||||||||||
|
Subroutine
preprocess_results_page: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 430 | 1 | my ( $self, $text ) = @_; | |||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||
| 432 | 1 | ▶ | return decode($self->{'charset'} || "utf8", $text); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'charset'} || 'utf8'
MC/DC0%0/1
$self->{'charset'} || 'utf8'
$self->{'charset'}
Truth table50%1/2
A
A= $self->{'charset'}
| |||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||
| 435 | 2 | ▶ | sub approximate_result_count ($) { | ||||||||||||||||||||||||||||||||
|
Subroutine
approximate_result_count: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 436 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||
| 438 | 2 | ▶ | my $str = $self->response->headers ()->header ("title") | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 439 | or return 0; | ||||||||||||||||||||||||||||||||||
| 440 | 2 | ▶ | if ($str =~ m#\((\d+)\)\s*$#) { # | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 441 | 0 | return $1; | |||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||
| 443 | 2 | return 0; | |||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||
| 446 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||
| 448 | __END__ | ||||||||||||||||||||||||||||||||||