Example usage for org.jsoup.nodes Element getElementsContainingText

List of usage examples for org.jsoup.nodes Element getElementsContainingText

Introduction

In this page you can find the example usage for org.jsoup.nodes Element getElementsContainingText.

Prototype

public Elements getElementsContainingText(String searchText) 

Source Link

Document

Find elements that contain the specified string.

Usage

From source file:org.brnvrn.Main.java

/**
 * Parse a tr HTML element describing the tool
 * @param tool is to be updated/* w w w. j ava 2s  .c om*/
 * @param tr   brings the data
 * @return true if successful
 */
private static boolean parseTrTool(Tool tool, Element tr) {
    boolean success = true;

    Element nameLink = tr.select("td:eq(0)").first();
    if (nameLink == null)
        return false;
    tool.setName(nameLink.text());
    tool.setUrl(nameLink.getElementsByTag("a").attr("href"));

    tool.setLicense(tr.select("td:eq(2)").first().text());

    tool.setCompatibility(tr.select("td:eq(3)").first().text());

    // More complicated: We will extract and remove known nodes, the rest will be description
    Element tdDescription = tr.select("td:eq(1)").first();
    Elements smalls = tdDescription.getElementsByTag("small");
    for (Element small : smalls) {
        Element author = small.getElementsContainingText("Author").first();
        if (author != null) {
            String authorsString = author.text();
            authorsString = authorsString.substring(authorsString.indexOf(":") + 1);
            tool.addAuthor(authorsString.split(","));
            small.remove();
        }
        Element sourceCode = small.getElementsContainingText("ource").last();
        if (sourceCode != null) {
            tool.setUrl_src(sourceCode.attr("href"));
            small.remove();
        }
    }
    tdDescription.getElementsByTag("br").remove();
    tool.setDescription(Jsoup.clean(tdDescription.html(), Whitelist.relaxed())); // ownText will miss the contained links in the description
    tool.setDescriptionText(tdDescription.text());

    bestEffortThemeLanguage(tool);

    return success;
}

From source file:eu.masconsult.bgbanking.banks.dskbank.DskClient.java

private boolean checkLoggedIn(Document doc) {
    Elements sup_links = doc.getElementsByClass("supplemental_links");
    if (sup_links == null || sup_links.size() == 0) {
        throw new ParseException("getBankAccounts: can't find .supplemental_links");
    }/*from   www .ja v  a  2 s. com*/
    for (Element sup_link : sup_links) {
        Elements exits = sup_link.getElementsContainingText("Log Out");
        if (exits != null && exits.size() > 0) {
            return true;
        }
    }
    return false;
}