Search in sources :

Example 1 with SelectorParseException

use of org.jsoup.select.Selector.SelectorParseException in project Lightning-Browser by anthonycr.

the class ArticleTextExtractor method extractAuthorDescription.

// Returns the author description or null
private String extractAuthorDescription(Document doc, String authorName) {
    String authorDesc = "";
    if (authorName.isEmpty())
        return "";
    // Special case for entrepreneur.com
    Elements matches = doc.select(".byline > .bio");
    if (matches != null && !matches.isEmpty()) {
        // assume it is the first.
        Element bestMatch = matches.first();
        authorDesc = bestMatch.text();
        return authorDesc;
    }
    // Special case for huffingtonpost.com
    matches = doc.select(".byline span[class*=teaser]");
    if (matches != null && !matches.isEmpty()) {
        // assume it is the first.
        Element bestMatch = matches.first();
        authorDesc = bestMatch.text();
        return authorDesc;
    }
    try {
        Elements nodes = doc.select(":containsOwn(" + authorName + ')');
        Element bestMatch = getBestMatchElement(nodes);
        if (bestMatch != null)
            authorDesc = bestMatch.text();
    } catch (SelectorParseException se) {
    // Avoid error when selector is invalid
    }
    return authorDesc;
}
Also used : Element(org.jsoup.nodes.Element) SelectorParseException(org.jsoup.select.Selector.SelectorParseException) Elements(org.jsoup.select.Elements)

Aggregations

Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1 SelectorParseException (org.jsoup.select.Selector.SelectorParseException)1