Something you can do is do an actual Google search programmatically for a start. The easiest way to do this is to access the URL https://www.google.com/search?q=QUERY_HERE , and then you want to clear the result from this page.
Here is a brief example of how to do this:
private static int getResultsCount(final String query) throws IOException { final URL url = new URL("https://www.google.com/search?q=" + URLEncoder.encode(query, "UTF-8")); final URLConnection connection = url.openConnection(); connection.setConnectTimeout(60000); connection.setReadTimeout(60000); connection.addRequestProperty("User-Agent", "Mozilla/5.0"); final Scanner reader = new Scanner(connection.getInputStream(), "UTF-8"); while(reader.hasNextLine()){ final String line = reader.nextLine(); if(!line.contains("<div id=\"resultStats\">")) continue; try{ return Integer.parseInt(line.split("<div id=\"resultStats\">")[1].split("<")[0].replaceAll("[^\\d]", "")); }finally{ reader.close(); } } reader.close(); return 0; }
To use, you should do something like:
final int count = getResultsCount("horses"); System.out.println("Estimated number of results for horses: " + count);
source share