2

How get google search results url?

(I use Zend_Gdata_Gbase for get search google results and not DomDocument/htmlsimpleparser because its looks to me that Zend_Gdata_Gbase done specially for parsing google results. if I wrong in my selection, please write.)

My function to get google search results for 'yahoo' or other query search string: (the function get a feed that should have search result for word 'yahoo', but when i use prin_t($feed) I don't see url for each result)

<?php    
function queryGoogleSearch($queryString='yahoo'){
            $service = new Zend_Gdata_Gbase();
            $query = $service->newSnippetQuery();
            $query->setBq('['.$queryString.']');
            $query->setOrderBy('modification_time');
            $query->setSortOrder('descending');
            $query->setMaxResults('4');
            $feed = $service->getGbaseSnippetFeed($query);
            return $feed; 
    }
    print_r(queryGoogleSearch());
?>

I get 4 first url results (when I search manually in google):

www.yahoo.com, mail.yahoo.com, search.yahoo.com, maps.yahoo.com

But I can't find them when I print $feed variable.

Please what should i change or add inqueryGoogleSearch() function? (Or other better code)

Thanks

Ben
  • 25,389
  • 34
  • 109
  • 165

1 Answers1

5

Are you trying to search google.com. Looks like that class is for Google Base, not google.com search engine. http://base.google.com/support/bin/answer.py?hl=en&answer=59260

You probably want this: http://code.google.com/apis/customsearch/v1/overview.html They recently just changed this. The old google search API has now deprecated as of Nov 1st. Custom search is the new API.

Its pretty simple to use without Zend.

http://code.google.com/apis/customsearch/v1/using_rest.html#WorkingResults

There is a JSON decoder in PHP. http://php.net/manual/en/function.json-decode.php

Hope that helps!

Matt
  • 7,049
  • 7
  • 50
  • 77
  • 1
    Thanks! but how can I use custom search if i need to make huge amount of searches and not 100 or a bit more? ("The API provides 100 search queries per day" http://code.google.com/apis/customsearch/v1/overview.html) – Ben Nov 07 '10 at 15:15
  • You can increase it if you need more. You will need a valid reason though. It looks like google is going away from the websearch api to start tracking it more. Sorry i can't give you a straight forward answer, but theres really no other way. Even if you used cURL to get the data using proxies and parse it out, google will still block you. – Matt Nov 07 '10 at 15:56
  • thank you very much! (are you sure that google will block me if i will used cURL + proxies? ) – Ben Nov 07 '10 at 17:03
  • It's very likely they will. Depending on the type of proxies you use and what not. They only allow so many hits in a certain period of time. You could try, but the best way to do it is just to use their API if you can. – Matt Nov 07 '10 at 19:11