Java Reference
In-Depth Information
/**
* Called to parse a table. The table number at the
* specified URL
* will be parsed.
* @param url The URL of the HTML page that contains the table.
* @param tableNum The table number to parse, zero for
* the first.
* @throws IOException Thrown if an error occurs while reading.
*/
public void process(URL url, int tableNum) throws IOException
{
InputStream is = url.openStream();
ParseHTML parse = new ParseHTML(is);
StringBuilder buffer = new StringBuilder();
List<String> list = new ArrayList<String>();
boolean capture = false;
advance(parse, "table", tableNum);
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
HTMLTag tag = parse.getTag();
if (tag.getName().equalsIgnoreCase("tr"))
{
list.clear();
capture = false;
buffer.setLength(0);
} else if (tag.getName().equalsIgnoreCase("/tr"))
{
if (list.size() > 0)
{
processTableRow(list);
list.clear();
}
} else if (tag.getName().equalsIgnoreCase("td"))
{
if (buffer.length() > 0)
list.add(buffer.toString());
buffer.setLength(0);
capture = true;
} else if (tag.getName().equalsIgnoreCase("/td"))
{
list.add(buffer.toString());
Search WWH ::




Custom Search