Java Utililty Methods HTML Jsoup Element

List of utility methods to do HTML Jsoup Element

Description

The list of methods to do HTML Jsoup Element are organized into topic(s).

Method

StringgetAuthorName(Element authorElement)
get Author Name
return authorElement.text().trim();
ListgetCodeSnippetCLT(Element codeElement, String content, String fqn, String api, String kind, String[] titles)
get Code Snippet CLT
List<Integer> indexes = new ArrayList<Integer>();
if (codeElement.tagName().equals("pre")) {
    if (content.startsWith("M")) {
        content = content.split(":")[2];
    } else if (content.startsWith("F")) {
        content = content.split(":")[3];
    } else {
        String[] tmp = content.split(":")[1].split("\\.");
...
DategetDate(Elements caption)
get Date
String date = caption.text();
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy");
return DateTime.parse(date, dtf).toDate();
DoublegetDouble(Elements line, int idx)
get Double
return Double.valueOf(line.get(idx).text());
ElementgetElementByXPath(String xpath, Document doc)
get Element By X Path
String[] tags = xpath.substring(11, xpath.length()).split("/"); 
Element clt = doc.body();
int index;
int divc = 0;
boolean done = false;
for (String tag : tags) {
    if (tag.startsWith("div"))
        divc++;
...
ElementsgetElementsByClass(String className, Element boardElement)
get Elements By Class
Elements elements = boardElement.getElementsByClass(className);
if (elements != null && !elements.isEmpty()) {
    return elements;
return null;
ListgetElementsFirstLevel(String html)
Return the first level of the elements given a element Body.
Document docu = Jsoup.parse(html);
List<Element> elements = new ArrayList<Element>();
for (Node node : docu.getAllElements()) {
    if (node instanceof Element && node.parentNode() != null && node.parentNode().equals(docu.body())) {
        elements.add((Element) node);
return elements;
...
StringgetElementTextBySelector(String html, String selector)
get Element Text By Selector
Document document = Jsoup.parse(html);
Elements e = document.select(selector);
if (e == null || e.isEmpty()) {
    return null;
return Jsoup.parse(e.toString()).text();
StringgetElementValue(Element wrapperElement, String cssQuery)
get Element Value
try {
    Element elm = wrapperElement.select(cssQuery).first();
    return elm.text();
} catch (Exception e) {
    e.printStackTrace();
    return "";
intgetElIndexInSameTags(Element e)
get El Index In Same Tags
Elements chs = e.parent().children();
int index = 1;
for (int i = 0; i < chs.size(); i++) {
    Element cur = chs.get(i);
    if (e.tagName().equals(cur.tagName())) {
        if (e.equals(cur)) {
            break;
        } else {
...