List of utility methods to do HTML Jsoup Element
boolean | isEmptyElement(Node node) is Empty Element if (node == null) { return false; if (node instanceof TextNode) { return StringUtil.isBlank(((TextNode) node).text()); if (!(node instanceof Element)) { return false; ... |
void | markAll(Elements tags) mark All markAll(tags, defaultColor); |
void | markChildren(Element tag, final String color) mark Children tag.traverse(new NodeVisitor() { @Override public void head(Node node, int i) { if (node instanceof Element) { Element tag = (Element) node; mark(tag, color); @Override public void tail(Node node, int i) { }); |
String | printNode(Element root) print Node return printNode(root, 0);
|
String | processCheck(Element ele, Element parent, String dict) process Check StringBuilder builder = new StringBuilder(); builder.append("<input name=\"").append(ele.attr("name")); builder.append("\" id=\"").append(ele.attr("id")); builder.append("\" style=\"").append(ele.attr("style")); builder.append("\" value=\""); builder.append("\" type=\"check\"/>"); builder.append(""); return builder.toString(); ... |
Element | randomElement() random Element return Jsoup.parse("<p>text</p>"); |
void | replaceHtml(Node element) replace Html List<Node> elements = element.childNodes(); Pattern compile = Pattern.compile("(?:https?|ftps?)://[\\w/%.-][/\\??\\w=?\\w?/%.-]?[/\\?&\\w=?\\w?/%.-]*"); for (int i = elements.size() - 1; i >= 0; i--) { Node node = elements.get(i); if (node instanceof TextNode) { String value = ((TextNode) node).text(); Matcher matcher = compile.matcher(value); if (matcher.find()) { ... |
int | sameTagElNums(Element e) same Tag El Nums Elements els = e.parent().getElementsByTag(e.tagName());
return els.size();
|
void | setAttribute(Element e, String key, String value) Set an attribute on an element (in the data-baleen namespace) e.attr(attributeKey(key), value); |
void | stripAttribute(Element body, String attribute) strip Attribute Elements elements = body.getElementsByAttribute(attribute);
for (Element e : elements) {
e.removeAttr(attribute);
|