Jodd jerry解析html

Jodd jerry解析html

1. 引入maven依赖



    org.jodd
    jodd-all
    5.1.0

2. 将html转换成dom

Jerry doc = Jerry.jerry(html);

3. 解析dom对象

// 查找

标签 doc.find("p") // 遍历dom对象 doc.each(new JerryFunction() { int p = 20; @Override public Boolean onNode(Jerry jerry, int index) { if ("p".equals(jerry.get(0).getNodeName()) && jerry.parent().get(0).getNodeName() == null) { p--; sb.append(jerry.htmlAll(true)); } return true; } });

参考官方文档:https://jodd.org/jerry/jerry-examples.html

你可能感兴趣的:(Jerry,java)