Java Reference
In-Depth Information
To run this spider, simply pass the URL of the website you wish to check as the first argu-
ment. For example, to spider the HTTP Recipes site, use the following command:
CheckLinks http://www.heatonreserach.com
The above command simply shows the abstract format to call this recipe, with the appro-
priate parameters. For exact information on how to run this recipe refer to Appendix B, C, or
D, depending on the operating system you are using. This recipe is made up of two classes.
The first, named CheckLinks , configures the spider and then begins processing. The
next class, named LinkReport , receives information from the spider and compiles a list
of bad links. We will examine each of classes, starting with CheckLinks .
Creating the Broken Links Spider
The CheckLinks class contains the main method for the recipe. Listing 13.4 shows
the CheckLinks class.
Listing 13.4: Find Broken Links (CheckLinks.java)
package com.heatonresearch.httprecipes.ch13.recipe1;
import java.net.*;
import com.heatonresearch.httprecipes.spider.*;
import com.heatonresearch.httprecipes.spider.workload.*;
import com.heatonresearch.httprecipes.spider.workload.memory.*;
public class CheckLinks {
/**
* Main method for the application.
*
* @param args
* Holds the website to check (i.e.
* http://www.httprecipes.com/)
*/
static public void main(String args[]) {
try {
if (args.length != 1) {
System.out.println(
"Usage: CheckLinks [website to check]");
} else {
CheckLinks links = new CheckLinks();
links.check(new URL(args[0]));
}
} catch (Exception e) {
Search WWH ::




Custom Search