-
May 30th, 2010, 05:52 AM
#1
Get total search results from Google
Hi,
Just wondering if anyone know whether if there is a way that I can directly send search query
to Google web service from within a java application and get the result back?
Basically I just need to know the total number of pages the result return. I know there used to be
a Google API called SOAP that let you do that but they discontinued it -_- and replace it with AJAX Search, which I am not sure how can I get it to work within java.
If anyone know a way or have other alternatives please let me know.
Cheer!
-
June 1st, 2010, 07:47 AM
#2
Re: Get total search results from Google
You can use the Google "AJAX" calls just like a regular HTTP call in Java. From the Google AJAX API:
the API exposes a raw RESTful interface that returns JSON encoded results that are easily processed by most languages and runtimes
So, you will get the search results back in JSON format which can easily be parsed.
So you can do something like this:
Code:
String query = "foo bar";
URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?start=0&rsz=large&v=1.0&q=" + query);
URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer", "http://www.somewebsite.com"); //this isn't needed
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
This will make the call to the Google AJAX site and return the response in the form of JSON. Now you just need to figure out how to parse it :P
There is a JSON Library that you can download and use in your application at http://www.json.org/java/.
Last edited by ProgramThis; June 2nd, 2010 at 08:11 AM.
-
June 1st, 2010, 05:21 PM
#3
Re: Get total search results from Google
Oh sweet, thank you very much!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|