Hello fellow monks. I've having issues with the REST::Google::Search module. I'm trying to iterate throught the pages of google search results based on the query I enter and then determine on which page a specific site is located. It might be my lack of understanding of the cursor which seems to contain the next iteration of results I need to view. I've tried doing it manually but if you run the code you'll see my issue. It reports the website on page '0' when it actually is on page '4' I've posted my code below
use warnings;
use strict;
use Data::Dumper;
use REST::Google::Search;
REST::Google::Search->http_referer('http://example.com');
SearchGoogle( 0 );
sub SearchGoogle {
my $start = shift;
#print "Looking from position: $start\n";
my $res = REST::Google::Search->new(
q => 'perl regex',
start => $start,
rsz => 'small',
);
if ( $res->responseStatus != 200 ) {
SearchGoogle( $start );
}
my $data = $res->responseData;
my $cursor = $data->cursor;
my $pages = $cursor->pages;
printf "current page index: %s\n", $cursor->currentPageIndex;
my @results = $data->results;
my $found = 0;
foreach my $r (@results) {
if ($r->url =~ /spaweditor.com/) {
$found = 1;
print "FOUND WEBSITE: on page " . $cursor->currentPageIndex .
+"\n";
exit;
}
}
if ( !$found ) {
$start += 4;
SearchGoogle( $start );
}
}
Can someone provide an example or point me in the right direction?
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.