Here you can find the source of getMoney(final Element container)
static int getMoney(final Element container)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; public class Main { static int getMoney(final Element container) { // Money rewards final List<Element> allMoneyElements = new ArrayList<Element>(); allMoneyElements.addAll(container.select("span.moneygold")); allMoneyElements.addAll(container.select("span.moneysilver")); allMoneyElements.addAll(container.select("span.moneycopper")); if (allMoneyElements.isEmpty()) { return 0; }/* w ww .ja v a 2 s . co m*/ // Find the leftmost money element (so we parse only the first group - second group is max level rewards) int money = 0; Element leftEl = null; for (final Element el : allMoneyElements) { if (leftEl == null || el.siblingIndex() < leftEl.siblingIndex()) { leftEl = el; } } Node node; // Parse all directly adjacent span nodes, possibly with whitespace in between for (node = leftEl; (node instanceof Element && ((Element) node).tagName().equals("span")) || (node instanceof TextNode && ((TextNode) node).text().trim().isEmpty()); node = node .nextSibling()) { if (!(node instanceof Element)) { continue; } final Element el = (Element) node; if (el.hasClass("moneygold")) { money += Integer.parseInt(el.ownText()) * 10000; } else if (el.hasClass("moneysilver")) { money += Integer.parseInt(el.ownText()) * 100; } else if (el.hasClass("moneycopper")) { money += Integer.parseInt(el.ownText()); } } // If the money group we just parsed is followed immediately by max level text, then it means that the only // money group is the max-level money group, so we should skip it. if (node instanceof TextNode && ((TextNode) node).text().trim().startsWith("if completed at level")) { return 0; } return money; } }