Hi list; Im trying parse a html code with multiple table tag
<html> <body> <table> <tr>1</tr> <tr>2</tr> <tr>3</tr> </table> <tr>4</tr> <tr>5</tr> <tr>6</tr> <table> </table> </body> </html>
I wanted to get text on the second table, how do i do that?
5 6 7
here is my code
public static void main(String[] args) throws Exception { try { Parser parser=new Parser("http://192.168.80.211/test/9.htm"); parser.registerScanners(); //important! parser.addScanner(new TableScanner(parser));
System.out.println("Parsing " + parser.getURL()); Node node;
for (NodeIterator i=parser.elements(); i.hasMoreNodes(); ) { if ((node=i.nextNode()) instanceof TableTag) { // if (((Tag)node).getTagName().compareToIgnoreCase("TABLE")==0) //{ System.out.println("Table:"+(((Tag)node).toHtml())); //}
} } } catch(ParserException e) { e.printStackTrace(); }
This is old code applicable to version 1.3. I recommend upgrading to 1.4.
Look inside the returned nodes with getChildren(). Or use Parser.extractAllNodesThatAre() to get a list. Or use a filter. See examples on the wiki.
Thank you the help i search on the list and found helfull tips.
Log in to post a comment.
Hi list;
Im trying parse a html code with multiple table tag
<html>
<body>
<table>
<tr>1</tr>
<tr>2</tr>
<tr>3</tr>
</table>
<tr>4</tr>
<tr>5</tr>
<tr>6</tr>
<table>
</table>
</body>
</html>
I wanted to get text on the second table, how do i do that?
5
6
7
here is my code
public static void main(String[] args) throws Exception
{
try
{
Parser parser=new Parser("http://192.168.80.211/test/9.htm");
parser.registerScanners(); //important!
parser.addScanner(new TableScanner(parser));
System.out.println("Parsing " + parser.getURL());
Node node;
for (NodeIterator i=parser.elements(); i.hasMoreNodes(); )
{
if ((node=i.nextNode()) instanceof TableTag)
{
// if (((Tag)node).getTagName().compareToIgnoreCase("TABLE")==0)
//{
System.out.println("Table:"+(((Tag)node).toHtml()));
//}
}
}
}
catch(ParserException e)
{
e.printStackTrace();
}
This is old code applicable to version 1.3.
I recommend upgrading to 1.4.
Look inside the returned nodes with getChildren().
Or use Parser.extractAllNodesThatAre() to get a list.
Or use a filter. See examples on the wiki.
Thank you the help i search on the list and found helfull tips.