473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2437
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("yourlicensekey");

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

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

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

while($search_counter <= $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_result)
{
if($err = $gs->getError())
{
echo "<br>Error: " . $err;
exit("<br>Exiting...");
}
}

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

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

//-- 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) | /\/ \ /

____________http://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
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...
8
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...
2
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...
6
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...
2
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...
5
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...
4
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...
2
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...
16
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.