473,785 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Google Hacks - Looping around the 10-result Limit in PHP

I have put together the Google Web API with PHP, as described in
O'Reilly's Google Hacks (Hack#55). However, the API only allows you to
return 10 results. Hack #51 shows how to Loop around the 10-result
limit but only describes how to do this in Perl. Anybody have this
book or know how I can get around this.

http://sundaystroll.com
Jul 17 '05 #1
2 2462
On 14 Mar 2004 13:57:16 -0800, jase hath writ:
I have put together the Google Web API with PHP, as described in
O'Reilly's Google Hacks (Hack#55). However, the API only allows you to
return 10 results. Hack #51 shows how to Loop around the 10-result
limit but only describes how to do this in Perl. Anybody have this
book or know how I can get around this.


I have the book -- just can't locate it now. :-) I remember
reading that section of the book and wondering "Why so much effort?"

Here's is my bookmark for starting an "Advanced Google Search":

http://www.google.com/advanced_searc...=en&lr=lang_en

Notice the num=50 , that does it for me in a browser.
If you only specify "simple search terms", it proceeds
v-a-v a "normal" Google search _and_ returns 50 (if there
were that many) hits.

HTH
Jonesy
--
| Marvin L Jones | jonz | W3DHJ | OS/2
| Gunnison, Colorado | @ | Jonesy | linux __
| 7,703' -- 2,345m | config.com | DM68mn SK
Jul 17 '05 #2
Hi Jase,

jase wrote:
I have put together the Google Web API with PHP, as described in
O'Reilly's Google Hacks (Hack#55). However, the API only allows you to
return 10 results. Hack #51 shows how to Loop around the 10-result
limit but only describes how to do this in Perl. Anybody have this
book or know how I can get around this.


Try this:

$search_perpage = 10;

//---------------------------------------------------------------//
// Ask GOOGLE
//---------------------------------------------------------------//
$gs = new GoogleSearch();

//set Google licensing key
$gs->setKey("yourli censekey");

//set max. number of results to be returned.
$gs->setMaxResults( $search_perpage );

$gs->setSafeSearch( true); //set Google "SafeSearch " feature.
$gs->setFilter(true );
$gs->setWSDLURL("Go ogleSearch.wsdl ");
$gs->setQueryString ($query); //set query string to search.

$search_runs = 5;
$search_counter = 1;
$count = 0;

while($search_c ounter <= $search_runs)
{
$startindex=(($ search_counter* $search_perpage )-$search_perpage );

$gs->setStartResult ($startindex);

//call search method on GoogleSearch object
$search_result = $gs->doSearch();

//check for errors
if(!$search_res ult)
{
if($err = $gs->getError())
{
echo "<br>Error: " . $err;
exit("<br>Exiti ng...");
}
}

$ranking[$query]["total"] =
$search_result->getEstimatedTo talResultsCount ();

//output individual components of each result
$re = $search_result->getResultEleme nts();

//-- Put the result in another data structure
foreach($re as $element)
{
$count++;
if(preg_match("/[\/|\.]$domain/",$element->getURL()))
{
$ranking[$query]["ranks"][$count]["title"]=
$element->getTitle();
$ranking[$query]["ranks"][$count]["url"] =
$element->getURL();

}

$search_counter ++;
}

Hope this helps.

Hartmut
--
SnakeLab - Internet und webbasierte Software | /\ /

Hartmut König (mailto:h.***** *@snakelab.de) | /\/ \ /

____________htt p://www.snakelab.de ________/\/\| /\/ \/

Kennen Sie Ihre Shopkunden ? ShopStat schon ->\/_____________

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2059
by: Tim Tyler | last post by:
The content from Google's web sites can no longer be displayed in frames :-( If anyone has a PHP screen-scraper and filter that rectifies this problem - by allowing "unframable" sites to be framed - could they please let me know! Thanks in advance for any assistance. -- __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
8
2801
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def _build_used(): .... y = x + 1 .... return x, y ....
2
2512
by: Stephen | last post by:
I have an array list alSearchCriteria which contains values which vary each time its created. It will always have 15 items in the arraylist each time its created. Some of the values in the array list will be a string called null. I want to create some way of looping through the arraylist and pulling back all the values which aren't null and displaying them on some control like a asp:label in .net. Does anyone know how I could write such...
6
1836
by: Mike | last post by:
Hello, This game will not loop. It compiles, builds, and executes fine, but the game will not loop around no matter what I do. What is wrong with the code? What do I have to add to make it loop till the person selects "N" or "n". #include <stdio.h> #include <stdlib.h>
2
22152
by: Stephen | last post by:
I have an array list alSearchCriteria which contains values which vary each time its created. It will always have 15 items in the arraylist each time its created. Some of the values in the array list will be a string called null. I want to create some way of looping through the arraylist and pulling back all the values which aren't null and displaying them on some control like a asp:label in .net. Does anyone know how I could write such...
5
3373
by: Stimp | last post by:
This is a question I'm carrying over from a previous one I made today since I've simplified where the problem is... I have a datatable, tblFeatures, which has around 30 columns (one for each 'feature'). I also have between 1 and 3 rows of data (one for each 'vehicle'). I want to transpose this table so that I ouput the rows horizontally and the columns vertically.
4
2242
by: Norman Fritag | last post by:
Hi there, >>>__ 1020.83, 2305.22, 1176.86, 755.12, 123.41 __ 1976.1, 1325.99, 947, 718.03, 414.32 __ 1020.83, 1976.1, 352.5, 947, 718.03, 366.98 Their IDs were as ---------------------------------------------- __ 508671, 508789, 508850, 513108, 514552 __ 507960, 509289, 509149, 511454, 512759__ 508671, 507960, 510436, 509149, 511454, 513633 <<<
2
1584
by: Delores | last post by:
I have been running make-table queries to create 10 tables (one for each unit) that are exported to Excel spreadsheets. Because of my limited knowledge with code, I've created 10 separate queries to do the job and then run a macro to do the exporting. I know there must be a way to generate the 10 tables with only one query and I think it probably involves looping(?) through the query. I've read the previous postings and anytime I try to...
16
1847
by: deko | last post by:
As I understand it, IE7 is still not standards compliant (although it has cleaned up some bugs). Can anyone point me to a summary of IE bugs and fixes? I've recently discovered Conditional Comments, which are supposed to be a reliable solution, such as this: <!--> <link rel="stylesheet" type="text/css" href="iestyle.css" /> <!--> This looks like a good way to go - that is, just use a separate stylesheet for
1
1292
by: gwenky | last post by:
Hello, so I was working this out yesterday and I am working on a function (w/o using arrays) that moves through the digits of a user inputted number and finds max/min ...this is the max option and it works ( up to < 10000), but I was wondering if there is a better format for looping this ...and if so where should I begin to look? int FindDigitAtPosition ( int x, double counter ) { for ( i = 1; i <= counter; ++i ) { if ( x < 10) {...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.