List of utility methods to do HTML Jsoup Element
void | addAllNodes(Element parent, List add All Nodes for (Node child : childNodes) {
parent.appendChild(child);
|
void | addProperty(Map add Property throw new UnsupportedOperationException("Fix This"); |
void | addStyle(Element element, String styleToBeAdded) Add style to existing one. String style = element.attr(ATTRIBUTE_STYLE); style += styleToBeAdded; element.attr(ATTRIBUTE_STYLE, style); |
Element | addTag(Element e, String tagName) add Tag return parse(e.toString()).body().tagName(tagName);
|
void | appendFragment(Element e, String fragment) append Fragment Element doc = Jsoup.parse(fragment); appendFragment(e, doc); |
void | appendText(Element element, StringBuffer stringBuffer) append Text List<Node> nodes = element.childNodes(); if (nodes != null && nodes.size() > 0) { for (int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); if (node instanceof TextNode) { String text = ((TextNode) node).text(); if (text.trim().length() > 0) { stringBuffer.append(text); ... |
Iterable | childrenByTag(final Element element, final String tag) children By Tag return Iterables.filter(element.children(), new Predicate<Element>() { public final boolean apply(final Element _element) { return _element.tagName().equals(tag); }); |
void | collectItemRewards(final Element icontab, final BiConsumer collect Item Rewards Objects.requireNonNull(icontab); final Map<String, String> itemNamesByIconId = new LinkedHashMap<>(); final Map<String, Integer> itemQuantitiesByIconId = new LinkedHashMap<>(); for (final Element iconPlaceholder : icontab.select("th[id]")) { final String iconId = iconPlaceholder.id(); final String itemName = iconPlaceholder.nextElementSibling().getElementsByTag("a").first().ownText(); itemNamesByIconId.put(iconId, itemName); final List<Element> itemScripts = icontab.ownerDocument().select("script:containsData(icontab)"); for (final Element script : itemScripts) { final Pattern iconInitRegex = Pattern.compile( Pattern.quote("$WH.ge('") + "([^']+)" + Pattern.quote("').appendChild(") + "[A-Za-z0-9_]+" + Pattern.quote(".createIcon(") + "[^\"]+\"([^\"]+)\"" + Pattern.quote("));")); final Matcher matcher = iconInitRegex.matcher(script.data()); while (matcher.find()) { itemQuantitiesByIconId.put(matcher.group(1), Integer.parseInt(matcher.group(2))); itemNamesByIconId.forEach((iconId, itemName) -> { Integer itemQuantity = itemQuantitiesByIconId.get(iconId); if (itemQuantity != null && (itemQuantity == 0 || itemQuantity == 1)) { itemQuantity = null; collector.accept(itemName, itemQuantity); }); |
String | collectTextUntilNextTag(final Element header, final String nextTagName) collect Text Until Next Tag final StringBuilder sb = new StringBuilder(); for (Node node = header.nextSibling(); !(node instanceof Element && ((Element) node).tagName().equals(nextTagName)); node = node.nextSibling()) { if (node instanceof TextNode) { sb.append(((TextNode) node).text()); } else if (node instanceof Element && ((Element) node).tagName().equals("br")) { sb.append("\n"); return sb.toString(); |
boolean | containsLink(Element element, String link) contains Link int links = 0; for (Element child : element.children()) { if (child.tagName().equals("a") && child.hasAttr("href") && child.attr("href").contains(link)) links++; return links > 0; |