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

StringgetSrcOrRelFromImageElement(Element imgElm)
get Src Or Rel From Image Element
if (imgElm.hasAttr("src"))
    return imgElm.attr("src");
return imgElm.attr("rel");
StringgetString(Elements td, int i)
get String
return td.get(i).text();
StringgetTextContent(Element node)
getTextContent avoid NullReferenceException
return (node == null) ? null : node.text();
StringgetTextFromAClass(Element doc, String location)
get Text From A Class
Element elementByItemprop = doc.select("a[class=" + location + "]").first();
String result = (elementByItemprop != null) ? elementByItemprop.text() : "none";
return result;
StringgetTextFromMultipleSelect(Element doc, String location, String locationValue)
get Text From Multiple Select
String[] locations = location.split(",");
String[] locationValues = locationValue.split(",");
Element currentElement = doc; 
int counter = 0;
for (int i = 0; i < (locations.length); i = +2) { 
    if (currentElement == null) {
        break;
    } else {
...
StringgetTextFromNodeIfAvailable(Element doc)
get Text From Node If Available
StringBuffer result = new StringBuffer();
for (Node child : doc.childNodes()) {
    if (child instanceof TextNode) {
        result.append(((TextNode) child).text());
return result.toString();
StringgetTextFromNodeSelect(Element doc, String location, String locationValue)
get Text From Node Select
String[] locations = location.split(",");
Element element = doc.select(locations[0] + "[" + locations[1] + "=" + locationValue + "]").first();
String result = (element != null) ? element.text() : "none";
return result.trim();
ElementgetTitle(Element el, String[] titles)
get Title
for (String title : titles)
    if (el.tagName().equals(title))
        return el;
Elements subsectionTitles = new Elements();
for (String title : titles)
    subsectionTitles.addAll(el.select(" " + title));
return subsectionTitles.get(0);
StringgetUserId(Element authorElement)
get User Id
String userIdUrL = authorElement.attr("href");
String userId = userIdUrL.substring(userIdUrL.indexOf("/citations?user=") + USER_URL_START_INDEX,
        userIdUrL.indexOf("/citations?user=") + USER_URL_END_INDEX);
return userId;
booleanisChildOf(Element child, Elements possibleParents)
Determines whether the given element is a child of one of the given parent elements.
for (Element parent : child.parents()) {
    if (possibleParents.contains(parent)) {
        return true;
return false;