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