Java Reference
In-Depth Information
}
For each search, a GoogleSearchResult object is returned. This object is ac-
cessed to obtain the GoogleSearchResultElement objects, which contain the
actual URL's found by the Google search.
if (r != null)
{
Object list[] = r.getResultElements();
resultCount = list.length;
Next, look through and obtain all of the GoogleSearchResultElement ob-
jects.
for (int i = 0; i < resultCount; i++)
{
GoogleSearchResultElement element =
(GoogleSearchResultElement) list[i];
result.add(element);
}
If fewer than ten items were returned in the search, then we have reached the end of the
search.
top = top + 10;
System.out.println(top);
} while (resultCount >= 10);
return result;
When the getResults function completes, we will have a list of all pages that con-
tain a reference to the target web site.
Getting a Link Count
It is also very easy to get a link count from Google. Simply perform a search on the target
URL, with the prefix “link:”, as seen here:
int result = 0;
search.setQueryString("link:" + url);
GoogleSearchResult r = null;
Next, the search is performed.
try
{
r = search.doSearch();
} catch (GoogleSearchFault e)
{
e.printStackTrace();
Search WWH ::




Custom Search