hii all, i am new to java and html parser.i want to extract text of first row within the first table of the following example HTML page: <html>
<body>
<h1> My First Page </h1>
<table> Student Detail <tr> <td> David </td> <td> John </td> </tr> <tr> <td> Vasu </td> <td> ali </td> </tr> </table>
</body>
</html>
i made a class like the following : public class ParsePage extends Parser {
public static void main(String args[]){ try{ //String p= args[0]; Parser parser = new Parser(args[0]); String [] tagsToBeFound = {"TABLE"}; TagFindingVisitor visitor = new TagFindingVisitor(tagsToBeFound); parser.visitAllNodesWith(visitor); Node [] alltableTags = visitor.getTags(0); System.out.println("First Table is "+alltableTags[0].toHtml()); Lexer lex=new Lexer(alltableTags[0].toHtml()); Parser newparse=new Parser(lex); String [] tagsultimate = {"tr"}; TagFindingVisitor visitor1 = new TagFindingVisitor(tagsultimate); Node [] alltrtags=visitor1.getTags(0); System.out.println("\\n First TableRow is : "+alltrtags[0].toHtml());
} catch(ParserException e) { System.out.println("Parsing error "+e); } } }
It is giving the correct first table in the output but while picking the first inner row it is giving exception. plz anyone help me out.....
What is the exception?
The exception is : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at ParsePage.main(ParsePage.java:43)
i.e. it can not find alltrtags[0] as the size of alltrtags is comming as 0.
I think you need a line like: newparse.visitAllNodesWith(visitor1); before trying to fetch with: Node [] alltrtags=visitor1.getTags(0);
Thanks a lot for help
Log in to post a comment.
hii all,
i am new to java and html parser.i want to extract text of first row within the first table of the following
example HTML page:
<html>
<body>
<h1> My First Page </h1>
<table>
Student Detail
<tr>
<td> David </td>
<td> John </td>
</tr>
<tr>
<td> Vasu </td>
<td> ali </td>
</tr>
</table>
</body>
</html>
i made a class like the following :
public class ParsePage extends Parser {
public static void main(String args[]){
try{
//String p= args[0];
Parser parser = new Parser(args[0]);
String [] tagsToBeFound = {"TABLE"};
TagFindingVisitor visitor = new TagFindingVisitor(tagsToBeFound);
parser.visitAllNodesWith(visitor);
Node [] alltableTags = visitor.getTags(0);
System.out.println("First Table is "+alltableTags[0].toHtml());
Lexer lex=new Lexer(alltableTags[0].toHtml());
Parser newparse=new Parser(lex);
String [] tagsultimate = {"tr"};
TagFindingVisitor visitor1 = new TagFindingVisitor(tagsultimate);
Node [] alltrtags=visitor1.getTags(0);
System.out.println("\\n First TableRow is : "+alltrtags[0].toHtml());
}
catch(ParserException e)
{
System.out.println("Parsing error "+e);
}
}
}
It is giving the correct first table in the output but while picking the first inner row it is giving exception.
plz anyone help me out.....
What is the exception?
The exception is :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ParsePage.main(ParsePage.java:43)
i.e. it can not find alltrtags[0] as the size of alltrtags is comming as 0.
I think you need a line like:
newparse.visitAllNodesWith(visitor1);
before trying to fetch with:
Node [] alltrtags=visitor1.getTags(0);
Thanks a lot for help