<dependency> <groupId>org.ops4j.pax.carrot</groupId> <artifactId>pax-carrot-htmlparser</artifactId> <version>1.0.0</version> </dependency> import org.ops4j.pax.carrot.htmlparser.CarrotHtmlParser; import org.ops4j.pax.carrot.htmlparser.DomNode; import org.ops4j.pax.carrot.htmlparser.HtmlParserTools; public class HtmlParserExample { public static void main(String[] args) throws Exception { String html = "<html><body><h1>Hello, Carrot HTML Parser!</h1></body></html>"; CarrotHtmlParser parser = new CarrotHtmlParser(); DomNode root = parser.parse(html); DomNode titleNode = HtmlParserTools.selectSingleNode(root, "h1"); System.out.println(titleNode.getTextContent()); } }


上一篇:
下一篇:
切换中文