Java Code Examples for org.jsoup.nodes.Element#previousElementSibling()

The following examples show how to use org.jsoup.nodes.Element#previousElementSibling() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathElementBuilder.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getAbsolutePathFromElement(Element element) {
    if (element.tagName().equalsIgnoreCase(HtmlElementStore.HTML_ELEMENT)) {
        return "";
    }
    if (!element.tagName().equalsIgnoreCase(HtmlElementStore.BODY_ELEMENT)) {
        int i = 0;
        Element currentElement = element;
        while (currentElement.previousElementSibling() != null) {
            currentElement = currentElement.previousElementSibling();
            i++;
        }
        return getAbsolutePathFromElement(element.parent()) + " > " + element.tagName() + ":eq(" + i + ")";
    } else {
        return HtmlElementStore.BODY_ELEMENT; 
    }
}
 
Example 2
Source File: Elements.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private Elements siblings(String query, boolean next, boolean all) {
    Elements els = new Elements();
    Evaluator eval = query != null? QueryParser.parse(query) : null;
    for (Element e : this) {
        do {
            Element sib = next ? e.nextElementSibling() : e.previousElementSibling();
            if (sib == null) break;
            if (eval == null)
                els.add(sib);
            else if (sib.is(eval))
                els.add(sib);
            e = sib;
        } while (all);
    }
    return els;
}
 
Example 3
Source File: Elements.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private Elements siblings(String query, boolean next, boolean all) {
    Elements els = new Elements();
    Evaluator eval = query != null? QueryParser.parse(query) : null;
    for (Element e : this) {
        do {
            Element sib = next ? e.nextElementSibling() : e.previousElementSibling();
            if (sib == null) break;
            if (eval == null)
                els.add(sib);
            else if (sib.is(eval))
                els.add(sib);
            e = sib;
        } while (all);
    }
    return els;
}
 
Example 4
Source File: StructuralEvaluator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();
    return prev != null && evaluator.matches(root, prev);
}
 
Example 5
Source File: StructuralEvaluator.java    From xsoup with MIT License 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();
    return prev != null && evaluator.matches(root, prev);
}
 
Example 6
Source File: StructuralEvaluator.java    From xsoup with MIT License 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();

    while (prev != null) {
        if (evaluator.matches(root, prev))
            return true;

        prev = prev.previousElementSibling();
    }
    return false;
}
 
Example 7
Source File: StructuralEvaluator.java    From jsoup-learning with MIT License 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();
    return prev != null && evaluator.matches(root, prev);
}
 
Example 8
Source File: StructuralEvaluator.java    From jsoup-learning with MIT License 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();

    while (prev != null) {
        if (evaluator.matches(root, prev))
            return true;

        prev = prev.previousElementSibling();
    }
    return false;
}
 
Example 9
Source File: PrecedingSiblingOneSelector.java    From JsoupXpath with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @return res
 */
@Override
public XValue apply(Elements context) {
    List<Element> total = new LinkedList<>();
    for (Element el : context){
        if (el.previousElementSibling()!=null){
            total.add(el);
        }
    }
    Elements newContext = new Elements();
    newContext.addAll(total);
    return XValue.create(newContext);
}
 
Example 10
Source File: CommonUtil.java    From JsoupXpath with Apache License 2.0 5 votes vote down vote up
public static Elements precedingSibling(Element el){
    Elements rs = new Elements();
    Element tmp = el.previousElementSibling();
    while (tmp!=null){
        rs.add(tmp);
        tmp = tmp.previousElementSibling();
    }
    if (rs.size() > 0){
        return rs;
    }
    return null;
}
 
Example 11
Source File: StructuralEvaluator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();
    return prev != null && evaluator.matches(root, prev);
}
 
Example 12
Source File: StructuralEvaluator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();

    while (prev != null) {
        if (evaluator.matches(root, prev))
            return true;

        prev = prev.previousElementSibling();
    }
    return false;
}
 
Example 13
Source File: AxisSelector.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
/**
 * 节点前面的全部同胞节点,preceding-sibling
 *
 * @param e
 * @return
 */
public Elements precedingSibling(Element e) {
    Elements rs = new Elements();
    Element tmp = e.previousElementSibling();
    while (tmp != null) {
        rs.add(tmp);
        tmp = tmp.previousElementSibling();
    }
    return rs;
}
 
Example 14
Source File: StructuralEvaluator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();

    while (prev != null) {
        if (evaluator.matches(root, prev))
            return true;

        prev = prev.previousElementSibling();
    }
    return false;
}
 
Example 15
Source File: StructuralEvaluator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();
    return prev != null && evaluator.matches(root, prev);
}
 
Example 16
Source File: StructuralEvaluator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();

    while (prev != null) {
        if (evaluator.matches(root, prev))
            return true;

        prev = prev.previousElementSibling();
    }
    return false;
}
 
Example 17
Source File: LinkElementSelector.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param element
 * @return whether one of the preceding sibling is of heading type
 */
private boolean isOneOfPrecedingSiblingofHeadingType(Element element) {
    Element prevElementSibling = element.previousElementSibling();
    while (prevElementSibling != null) {
        if (PREV_SIBLING_CONTEXT_ELEMENTS.contains(prevElementSibling.tagName()) || 
                !prevElementSibling.select(CssLikeQueryStore.HEADINGS_CSS_LIKE_QUERY).isEmpty()) {
            return true;
        }
        prevElementSibling = prevElementSibling.previousElementSibling();
    }
    return false;
}
 
Example 18
Source File: StructuralEvaluator.java    From zongtui-webcrawler with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();
    return prev != null && evaluator.matches(root, prev);
}
 
Example 19
Source File: StructuralEvaluator.java    From zongtui-webcrawler with GNU General Public License v2.0 5 votes vote down vote up
public boolean matches(Element root, Element element) {
    if (root == element)
        return false;

    Element prev = element.previousElementSibling();

    while (prev != null) {
        if (evaluator.matches(root, prev))
            return true;

        prev = prev.previousElementSibling();
    }
    return false;
}
 
Example 20
Source File: AxisSelector.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
/**
 * 返回前一个同胞节点(扩展),语法 preceding-sibling-one
 *
 * @param e
 * @return
 */
public Elements precedingSiblingOne(Element e) {
    Elements rs = new Elements();
    if (e.previousElementSibling() != null) {
        rs.add(e.previousElementSibling());
    }
    return rs;
}