Source Code : HTML parser based on HTMLEditorKit.ParserCallback
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
HTML parser based on HTMLEditorKit.ParserCallback
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
public class Main {
public static void main(String args[]) throws Exception {
URL url = new URL(args[0]);
Reader reader = new InputStreamReader((InputStream) url.getContent());
new ParserDelegator().parse(reader, new HTMLParse(), false);
}
}
class HTMLParse extends HTMLEditorKit.ParserCallback {
public void handleText(char[] data, int pos) {
System.out.println(data);
}
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
System.out.println("+" + t.toString());
}
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
System.out.println("*" + t.toString());
}
public void handleEndTag(HTML.Tag t, int pos) {
System.out.println("-" + t.toString());
}
}
Thank with us