Java Reference
In-Depth Information
} else
{
System.out.println("Error logging in.");
}
}
/*
* Simple main method to create an instance of the object and
* call the process method.
*/
public static void main(String args[])
{
try
{
Cookieless cookieless = new Cookieless();
cookieless.process("falken", "joshua", "Mi", "s");
} catch (Exception e)
{
e.printStackTrace();
}
}
}
There are three primary methods that are used in this recipe. The first, named
process
,
manages the bot's progress and calls the other two methods. The second, named
login
,
logs the user into the system. The third, called
search
, is called by the process method to
perform the search.
The Process Method
The
process
method is called by the
main
method. The
process
method is
passed four parameters. The parameter
uid
specifies the user id,
pwd
specifies the pass-
word,
search
specifies what to search for and
type
specifies the type of search. Two
search types are supported: a search type of āsā for states or ācā for capitols.
The
process
method begins by calling the
login
method. If the
login
method
was successful, then a session id is returned. This session id will be necessary to perform the
search, because the web site requires that you be logged in to perform the search.
String session = login(uid, pwd);
if (session != null)
{
If a session id was returned, then the
search
function is called. The
search
func-
tion returns a list of states that matched the search.
List<String> list = search(session, search, type);
for (String item : list)