Java Reference
In-Depth Information
/**
* This method is called to download article text from each
* article page.
* @param url The URL to download from.
* @return The article text from the specified page.
* @throws IOException Thrown if a communication error occurs.
*/
private String downloadArticlePage(URL url) throws IOException
{
final String token = "<center>";
String contents = downloadPage(url);
String result = extractNoCase(contents,token,token,0);
return token+result;
}
/**
* This method looks for each of the <option> tags that contain
* a link to each of the pages. For each page found the
* downloadArticlePage method is called.
*/
public void process()
throws IOException
{
URL url =
new URL("http://www.httprecipes.com/1/9/article.php");
InputStream is = url.openStream();
ParseHTML parse = new ParseHTML(is);
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
HTMLTag tag = parse.getTag();
if (tag.getName().equalsIgnoreCase("option"))
{
String str = tag.getAttributeValue("value");
URL u = new URL(url,str);
System.out.println(downloadArticlePage(u));
}
}
}
}
Search WWH ::




Custom Search