import net.htmlparser.jericho.*;
public class HTMLParserExample {
public static void main(String[] args) throws Exception {
String html = "<html><body><h1>Title</h1><p>Paragraph</p></body></html>";
Source source = new Source(html);
source.fullSequentialParse();
Element titleElement = source.getFirstElement(HTMLElementName.H1);
String title = titleElement.getTextExtractor().toString();
Element paragraphElement = source.getFirstElement(HTMLElementName.P);
String paragraph = paragraphElement.getTextExtractor().toString();
System.out.println("Title: " + title);
System.out.println("Paragraph: " + paragraph);
}
}
import net.htmlparser.jericho.*;
public class HTMLParserExample {
private static Source source;
public static void main(String[] args) throws Exception {
String html = "<html><body><h1>Title</h1><p>Paragraph</p></body></html>";
if (source == null) {
source = new Source(html);
source.fullSequentialParse();
}
Element titleElement = source.getFirstElement(HTMLElementName.H1);
String title = titleElement.getTextExtractor().toString();
Element paragraphElement = source.getFirstElement(HTMLElementName.P);
String paragraph = paragraphElement.getTextExtractor().toString();
System.out.println("Title: " + title);
System.out.println("Paragraph: " + paragraph);
}
}
import net.htmlparser.jericho.*;
public class HTMLParserExample {
public static void main(String[] args) throws Exception {
String html = "<html><body><h1>Title</h1><p>Paragraph</p></body></html>";
Source source = new Source(html);
source.fullSequentialParse();
Segment titleSegment = new Segment(source, 0, html.indexOf("</h1>") + 5);
Segment paragraphSegment = new Segment(source, html.indexOf("<p>"), html.indexOf("</p>") + 4);
Element titleElement = new Element(titleSegment, HTMLElementName.H1, StartTagType.NORMAL, EndTagType.NORMAL);
String title = titleElement.getTextExtractor().toString();
Element paragraphElement = new Element(paragraphSegment, HTMLElementName.P, StartTagType.NORMAL, EndTagType.NORMAL);
String paragraph = paragraphElement.getTextExtractor().toString();
System.out.println("Title: " + title);
System.out.println("Paragraph: " + paragraph);
}
}