/**
* @(#)VisitorsTest.java
*
*
* @author
* @version 1.00 2009/6/18
*/
import org.htmlparser.Parser;
import org.htmlparser.Node;
import org.htmlparser.util.NodeList;
import org.htmlparser.nodes.*;
import org.htmlparser.visitors.*;
import org.htmlparser.Tag;
import org.htmlparser.tags.*;
public class VisitorsTest extends NodeVisitor{
public VisitorsTest() {
}
public static void main(String args[]){
try{
String path="file:///c:/htmlparsertest.html";
Parser pr = new Parser(path);
// pr.setURL("http://www.suse.edu.cn");
VisitorsTest vt = new VisitorsTest();
pr.visitAllNodesWith(vt);
}
catch(Exception e){
e.printStackTrace();
}
}
public void visitTag (Tag tag)
{
System.out.print ("\nTagName:" + tag.getTagName () );
if(tag instanceof LinkTag){
LinkTag lt = (LinkTag)tag;
System.out.print(" LinkTag is:"+ lt.extractLink());
}
else if(tag instanceof FormTag){
FormTag ft = (FormTag)tag;
System.out.print(" FormTag is:"+ft.getFormName());
}
else if(tag instanceof ImageTag){
ImageTag it = (ImageTag)tag;
System.out.print(" ImageTag url is:"+it.getImageURL());
}
else {
System.out.print(" OtherTag");
}
}
}