<dependency>
<groupId>org.ops4j.pax.carrot</groupId>
<artifactId>org.ops4j.pax.carrot.html</artifactId>
<version>1.3.0</version>
</dependency>
import org.ops4j.pax.carrot.api.CarrotException;
import org.ops4j.pax.carrot.api.ExecutionContext;
import org.ops4j.pax.carrot.html.HTMLElement;
import org.ops4j.pax.carrot.html.HTMLParser;
public class HTMLParserExample {
public static void main(String[] args) {
try {
HTMLElement htmlElement = HTMLParser.parse("<html><head><title>OPS4J Pax Carrot</title></head><body><h1>Welcome to OPS4J Pax Carrot HTML Parser</h1></body></html>");
String title = htmlElement.find("title").text();
System.out.println("Title: " + title);
String body = htmlElement.find("body").text();
System.out.println("Body: " + body);
} catch (CarrotException e) {
e.printStackTrace();
}
}
}
import org.ops4j.pax.carrot.api.ExecutionContext;
import org.ops4j.pax.carrot.html.HTMLParser;
import java.util.HashMap;
import java.util.Map;
public class HTMLParserConfigurationExample {
public static void main(String[] args) {
Map<String, Object> settings = new HashMap<>();
try {
ExecutionContext context = HTMLParser.createExecutionContext(settings);
HTMLParser htmlParser = HTMLParser.create(context);
// ...
} catch (Exception e) {
e.printStackTrace();
}
}
}