Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1071343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:42:12+00:00 2026-05-16T20:42:12+00:00

Does anyone know if and how it is possible to search Google programmatically –

  • 0

Does anyone know if and how it is possible to search Google programmatically – especially if there is a Java API for it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:42:12+00:00Added an answer on May 16, 2026 at 8:42 pm

    Some facts:

    1. Google offers a public search webservice API which returns JSON: http://ajax.googleapis.com/ajax/services/search/web. Documentation here

    2. Java offers java.net.URL and java.net.URLConnection to fire and handle HTTP requests.

    3. JSON can in Java be converted to a fullworthy Javabean object using an arbitrary Java JSON API. One of the best is Google Gson.

    Now do the math:

    public static void main(String[] args) throws Exception {
        String google = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
        String search = "stackoverflow";
        String charset = "UTF-8";
        
        URL url = new URL(google + URLEncoder.encode(search, charset));
        Reader reader = new InputStreamReader(url.openStream(), charset);
        GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);
        
        // Show title and URL of 1st result.
        System.out.println(results.getResponseData().getResults().get(0).getTitle());
        System.out.println(results.getResponseData().getResults().get(0).getUrl());
    }
    

    With this Javabean class representing the most important JSON data as returned by Google (it actually returns more data, but it’s left up to you as an exercise to expand this Javabean code accordingly):

    public class GoogleResults {
    
        private ResponseData responseData;
        public ResponseData getResponseData() { return responseData; }
        public void setResponseData(ResponseData responseData) { this.responseData = responseData; }
        public String toString() { return "ResponseData[" + responseData + "]"; }
    
        static class ResponseData {
            private List<Result> results;
            public List<Result> getResults() { return results; }
            public void setResults(List<Result> results) { this.results = results; }
            public String toString() { return "Results[" + results + "]"; }
        }
    
        static class Result {
            private String url;
            private String title;
            public String getUrl() { return url; }
            public String getTitle() { return title; }
            public void setUrl(String url) { this.url = url; }
            public void setTitle(String title) { this.title = title; }
            public String toString() { return "Result[url:" + url +",title:" + title + "]"; }
        }
    
    }
    

    ###See also:

    • How to fire and handle HTTP requests using java.net.URLConnection
    • How to convert JSON to Java

    Update since November 2010 (2 months after the above answer), the public search webservice has become deprecated (and the last day on which the service was offered was September 29, 2014). Your best bet is now querying http://www.google.com/search directly along with a honest user agent and then parse the result using a HTML parser. If you omit the user agent, then you get a 403 back. If you’re lying in the user agent and simulate a web browser (e.g. Chrome or Firefox), then you get a way much larger HTML response back which is a waste of bandwidth and performance.

    Here’s a kickoff example using Jsoup as HTML parser:

    String google = "http://www.google.com/search?q=";
    String search = "stackoverflow";
    String charset = "UTF-8";
    String userAgent = "ExampleBot 1.0 (+http://example.com/bot)"; // Change this to your company's name and bot homepage!
    
    Elements links = Jsoup.connect(google + URLEncoder.encode(search, charset)).userAgent(userAgent).get().select(".g>.r>a");
    
    for (Element link : links) {
        String title = link.text();
        String url = link.absUrl("href"); // Google returns URLs in format "http://www.google.com/url?q=<url>&sa=U&ei=<someKey>".
        url = URLDecoder.decode(url.substring(url.indexOf('=') + 1, url.indexOf('&')), "UTF-8");
        
        if (!url.startsWith("http")) {
            continue; // Ads/news/etc.
        }
        
        System.out.println("Title: " + title);
        System.out.println("URL: " + url);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if it's possible to have the adapter for an AutoCompleteTextView search
does anyone know if it is possible to concatenate matches resulting from a search
Does anyone know if something like this is possible? Do a quick search, using
Does anyone know if there is some parameter available for programmatic search on yahoo
Does anyone know if its possible to use phing to copy an entire folder
Does anyone know if its possible to turn off dreamweavers custom icons that it
Does anyone know if its possible to set the amount of memory available in
I was wondering does anyone know if its possible to open a wifi and
Does anyone know whether it is possible to refer to another section from the
Does anyone know if this is possible? I can't see to find much info

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.