Java Reference
In-Depth Information
/**
* Called to extract a list from the specified URL.
* @param url The URL to extract the list from.
* @param listType What type of list, specify its beginning
* tag (i.e. <UL>).
* @param optionList Which list to search, zero for first.
* @throws IOException Thrown if an IO exception occurs.
*/
public void process(URL url, String listType, int optionList)
throws IOException
{
String listTypeEnd = listType + "/";
InputStream is = url.openStream();
ParseHTML parse = new ParseHTML(is);
StringBuilder buffer = new StringBuilder();
boolean capture = false;
advance(parse, listType, optionList);
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
HTMLTag tag = parse.getTag();
if (tag.getName().equalsIgnoreCase("li"))
{
if (buffer.length() > 0)
processItem(buffer.toString());
buffer.setLength(0);
capture = true;
} else if (tag.getName().equalsIgnoreCase("/li"))
{
System.out.println(buffer.toString());
processItem(buffer.toString());
buffer.setLength(0);
capture = false;
} else if (tag.getName().equalsIgnoreCase(listTypeEnd))
{
break;
}
} else
{
if (capture)
buffer.append((char) ch);
}
Search WWH ::




Custom Search