Java Reference
In-Depth Information
/**
* Process each sub page. The sub pages are where the data
* actually is.
* @param u The URL of the sub page.
* @throws IOException Thrown if an error occurs while
* processing.
*/
private void processSubPage(URL u) throws IOException
{
String str = downloadPage(u, 5000);
String code = extractNoCase(str,
"Code:<b></td><td>", "</td>", 0);
if (code != null)
{
String capital = extractNoCase(str,
"Capital:<b></td><td>", "</td>", 0);
String name = extractNoCase(str, "<h1>", "</h1>", 0);
String flag = extractNoCase(str, "<img src=\"", "\"
border=\"1\">", 2);
String site = extractNoCase(str,
"Official Site:<b></td><td><a href=\"",
"\"", 0);
URL flagURL = new URL(u, flag);
StringBuilder buffer = new StringBuilder();
buffer.append("\"");
buffer.append(code);
buffer.append("\",\"");
buffer.append(name);
buffer.append("\",\"");
buffer.append(capital);
buffer.append("\",\"");
buffer.append(flagURL.toString());
buffer.append("\",\"");
buffer.append(site);
buffer.append("\"");
System.out.println(buffer.toString());
}
}
/**
* This method downloads the specified URL into a Java
* String. This is a very simple method, that you can
* reused anytime you need to quickly grab all data from
* a specific URL.
Search WWH ::




Custom Search