Java Reference
In-Depth Information
This recipe will create a bot that will scan sites that contain information about a famous
person that you will choose. The bot will attempt to obtain the person's birth year. The bot
works by calling on Google to find web sites that contain the person's name. The bot then
scans the HTML of each of these pages looking for the person's birth year.
This recipe is shown in Listing 11.6.
Listing 11.6: A Google Hybrid Bot (WhenBorn.java)
package com.heatonresearch.httprecipes.ch11.recipe3;
import com.google.soap.search.*;
import com.heatonresearch.httprecipes.html.ParseHTML;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
public class WhenBorn
{
/*
* The key that Google provides anyone who uses their API.
*/
static String key;
/*
* The search object to use.
*/
static GoogleSearch search;
/*
* This map stores a mapping between a year, and how
* many times that year has come up as a potential birth year.
*/
private Map<Integer, Integer> results =
new HashMap<Integer, Integer>();
/**
* Perform a Google search and return the results. Only return
* 100 results.
* @param query What to search for.
* @return The results of the Google search.
*/
public Collection<GoogleSearchResultElement>
Search WWH ::




Custom Search