List of utility methods to do HTML Jsoup Element
Optional | getFirstWithOwnText(final Elements elementList, final String text) get First With Own Text return elementList.stream().filter(el -> el.ownText().equals(text)).findFirst();
|
String | getFormattedText(Element element) Given a jsoup element, gets all contained text preserving formatting by tags such as StringBuilder stringBuilder = new StringBuilder(); element.childNodes().forEach(node -> { if (node instanceof TextNode) { stringBuilder.append(((TextNode) node).text()); } else if (node instanceof Element) { if ("br".equalsIgnoreCase(((Element) node).tag().getName())) { stringBuilder.append("\n"); } else { ... |
String | getIndustry(Element element) get Industry return element.select("span.industry").text(); |
int | getInt(Elements td, int i) get Int String s = getString(td, i); String n = isNullOrEmpty(s) ? "-1" : s; return Integer.parseInt(n); |
String | getLink(Element element, int index) get Link try { List<Element> elements = element.getElementsByTag("a"); return elements.get(index).attr("href"); } catch (IndexOutOfBoundsException e) { throw new NullPointerException(); |
int | getMoney(final Element container) get Money 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; int money = 0; ... |
String | getNameFromAttributes(org.jsoup.nodes.Element e) checks whether the attributes values to be used as variable name String id = e.attr("id"); String name = e.attr("name"); String value = e.attr("value"); String _class = e.attr("class"); String action = e.attr("action"); String text = e.text(); text = text.replaceAll("\t", "_"); text = text.replaceAll("\n", "_"); ... |
Element | getOneSubItemOfClass(Element parent, String className) get One Sub Item Of Class return getOneSubItemOfClass(parent, "div", className); |
String | getReviewAuthorIDFromMultipleSelect(Element doc, String location, String locationValue) get Review Author ID From Multiple Select String author_id = getAttributeFromMultipleSelect(doc, location, locationValue); if (!author_id.equals("none")) { author_id = (author_id != null) ? (author_id.split("=")[1]) : "none"; return author_id.trim(); |
Element | getSingleElement(final Elements elements) get Single Element if (elements.size() != 1) { throw new IllegalArgumentException( "A single element matching the criteria was expected. Instead, found " + elements.size()); return elements.first(); |