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

  • Home
  • SEARCH
  • 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 8197661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:47:16+00:00 2026-06-07T05:47:16+00:00

The following code taken from: Java code for using google custom search API .

  • 0

The following code taken from: Java code for using google custom search API. It works correctly to extract the first 10 results of the first page in google results pages.

public static void main(String[] args) throws Exception {      
String key="YOUR KEY";     
String qry="Android";     
URL url = new URL("https://www.googleapis.com/customsearch/v1?
key="+key+ "&cx=013036536707430787589:_pqjad5hr1a&q="+ qry + "&alt=json");     

HttpURLConnection conn = (HttpURLConnection) url.openConnection();    
conn.setRequestMethod("GET");     
conn.setRequestProperty("Accept", "application/json");     
BufferedReader br = 
new BufferedReader(new InputStreamReader( (conn.getInputStream())));      
String output;     
System.out.println("Output from Server .... \n");     
while ((output = br.readLine()) != null) 
 {          
    if(output.contains("\"link\": \""))
    {                             
     String link=output.substring(output.indexOf("\"link\": \"")+
     ("\"link\": \"").length(), output.indexOf("\","));             
     System.out.println(link);       //Will print the google search links         
    }          
 }     
conn.disconnect();                               
}

I’m trying to figure out how can I traverse all results pages? By searching in https://developers.google.com/custom-search/v1/using_rest I found that the start parameter in the query referes to the index, and it is obvious that by changing this value in a loop this will do the purpose, but will cost me a query for each page (which should not be the case, as it is not a new query, it is the same query but just new page). Also, I found that google have mentioned that if the query succeeds, the response data contains value totalResults for total results, but they mentioned that it is estimate number. So, how can one get benifit of this service and get the actual number of results or number of pages in order to traverse them all ?? It does not make any sense that I issue new query for every page.

  • 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-06-07T05:47:17+00:00Added an answer on June 7, 2026 at 5:47 am
    1. You should use a JSON parser to extract data from the results, rather than parsing the result yourself.

    2. Google won’t return all the results at once for a single query. If you search for Java, there are approximately 214,000,000 results? Returning them all would last days, and you couldn’t do anything meaningful with them anyway. So if there are several pages, you must do a new query for each page, as you do when doing a Google search with your browser. Mostof the time, the interesting results are in the first or second page. Returning more than that would waste resources.

    3. Google doesn’t know the exact number of results. It returns an estimate. Counting the exact number of results would be too hard. Knowing that there are 214,000,001 results and not 214,000,002 doesn’t ad any value, and the exact number would be immediately obsolete anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code, taken partly from a Red Black Tree Java implementation.
I've used the following code, taken from here , to create my own custom
The following code is taken from here . I removed all Windows NT part
I have the following piece of code taken from the PHP manual on the
Is this possible to do the following in ExpressionEngine: (code taken from here )
How should I understand $(select option:selected) in the following code ? (taken from here
Hey all, the following is a snippet of code taken from the unix ptx
Till now I had been using following code to ftp file from one location
I have the following piece of code that is taken from a mock exam
I am using the following code to play a sound file using the java

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.