Java Code Examples for org.jsoup.select.Collector

The following are top voted examples for showing how to use org.jsoup.select.Collector. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: sipsoup   File: CacheCSSFunction.java   Source Code and License 5 votes vote down vote up
@Override
public Elements call(Element e, List<String> args) {
    try {
        return Collector.collect(cache.get(args.get(0)), e);
    } catch (ExecutionException e1) {
        log.warn("error when loader css query rule cache", e1);
    }
    return e.select(args.get(0));// 发生异常则服务降级
}
 
Example 2
Project: common   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Finds elements, including and recursively under this element, with the specified tag name.
 * @param tagName The tag name to search for (case insensitively).
 * @return a matching unmodifiable list of elements. Will be empty if this element and none of its children match.
 */
public Elements getElementsByTag(String tagName) {
    Validate.notEmpty(tagName);
    tagName = tagName.toLowerCase().trim();

    return Collector.collect(new Evaluator.Tag(tagName), this);
}
 
Example 3
Project: common   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find an element by ID, including or under this element.
 * <p>
 * Note that this finds the first matching ID, starting with this element. If you search down from a different
 * starting point, it is possible to find a different element by ID. For unique element by ID within a Document,
 * use {@link Document#getElementById(String)}
 * @param id The ID to search for.
 * @return The first matching element by ID, starting with this element, or null if none found.
 */
public Element getElementById(String id) {
    Validate.notEmpty(id);
    
    Elements elements = Collector.collect(new Evaluator.Id(id), this);
    if (elements.size() > 0)
        return elements.get(0);
    else
        return null;
}
 
Example 4
Project: common   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have a named attribute set. Case insensitive.
 *
 * @param key name of the attribute, e.g. {@code href}
 * @return elements that have this attribute, empty if none
 */
public Elements getElementsByAttribute(String key) {
    Validate.notEmpty(key);
    key = key.trim().toLowerCase();

    return Collector.collect(new Evaluator.Attribute(key), this);
}
 
Example 5
Project: common   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have an attribute name starting with the supplied prefix. Use {@code data-} to find elements
 * that have HTML5 datasets.
 * @param keyPrefix name prefix of the attribute e.g. {@code data-}
 * @return elements that have attribute names that start with with the prefix, empty if none.
 */
public Elements getElementsByAttributeStarting(String keyPrefix) {
    Validate.notEmpty(keyPrefix);
    keyPrefix = keyPrefix.trim().toLowerCase();

    return Collector.collect(new Evaluator.AttributeStarting(keyPrefix), this);
}
 
Example 6
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Finds elements, including and recursively under this element, with the specified tag name.
 * @param tagName The tag name to search for (case insensitively).
 * @return a matching unmodifiable list of elements. Will be empty if this element and none of its children match.
 */
public Elements getElementsByTag(String tagName) {
    Validate.notEmpty(tagName);
    tagName = tagName.toLowerCase().trim();

    return Collector.collect(new Evaluator.Tag(tagName), this);
}
 
Example 7
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find an element by ID, including or under this element.
 * <p>
 * Note that this finds the first matching ID, starting with this element. If you search down from a different
 * starting point, it is possible to find a different element by ID. For unique element by ID within a Document,
 * use {@link Document#getElementById(String)}
 * @param id The ID to search for.
 * @return The first matching element by ID, starting with this element, or null if none found.
 */
public Element getElementById(String id) {
    Validate.notEmpty(id);
    
    Elements elements = Collector.collect(new Evaluator.Id(id), this);
    if (elements.size() > 0)
        return elements.get(0);
    else
        return null;
}
 
Example 8
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have a named attribute set. Case insensitive.
 *
 * @param key name of the attribute, e.g. {@code href}
 * @return elements that have this attribute, empty if none
 */
public Elements getElementsByAttribute(String key) {
    Validate.notEmpty(key);
    key = key.trim().toLowerCase();

    return Collector.collect(new Evaluator.Attribute(key), this);
}
 
Example 9
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have an attribute name starting with the supplied prefix. Use {@code data-} to find elements
 * that have HTML5 datasets.
 * @param keyPrefix name prefix of the attribute e.g. {@code data-}
 * @return elements that have attribute names that start with with the prefix, empty if none.
 */
public Elements getElementsByAttributeStarting(String keyPrefix) {
    Validate.notEmpty(keyPrefix);
    keyPrefix = keyPrefix.trim().toLowerCase();

    return Collector.collect(new Evaluator.AttributeStarting(keyPrefix), this);
}
 
Example 10
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Finds elements, including and recursively under this element, with the specified tag name.
 * @param tagName The tag name to search for (case insensitively).
 * @return a matching unmodifiable list of elements. Will be empty if this element and none of its children match.
 */
public Elements getElementsByTag(String tagName) {
    Validate.notEmpty(tagName);
    tagName = normalize(tagName);

    return Collector.collect(new Evaluator.Tag(tagName), this);
}
 
Example 11
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find an element by ID, including or under this element.
 * <p>
 * Note that this finds the first matching ID, starting with this element. If you search down from a different
 * starting point, it is possible to find a different element by ID. For unique element by ID within a Document,
 * use {@link Document#getElementById(String)}
 * @param id The ID to search for.
 * @return The first matching element by ID, starting with this element, or null if none found.
 */
public Element getElementById(String id) {
    Validate.notEmpty(id);
    
    Elements elements = Collector.collect(new Evaluator.Id(id), this);
    if (elements.size() > 0)
        return elements.get(0);
    else
        return null;
}
 
Example 12
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have a named attribute set. Case insensitive.
 *
 * @param key name of the attribute, e.g. {@code href}
 * @return elements that have this attribute, empty if none
 */
public Elements getElementsByAttribute(String key) {
    Validate.notEmpty(key);
    key = key.trim();

    return Collector.collect(new Evaluator.Attribute(key), this);
}
 
Example 13
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have an attribute name starting with the supplied prefix. Use {@code data-} to find elements
 * that have HTML5 datasets.
 * @param keyPrefix name prefix of the attribute e.g. {@code data-}
 * @return elements that have attribute names that start with with the prefix, empty if none.
 */
public Elements getElementsByAttributeStarting(String keyPrefix) {
    Validate.notEmpty(keyPrefix);
    keyPrefix = keyPrefix.trim();

    return Collector.collect(new Evaluator.AttributeStarting(keyPrefix), this);
}
 
Example 14
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Finds elements, including and recursively under this element, with the specified tag name.
 * @param tagName The tag name to search for (case insensitively).
 * @return a matching unmodifiable list of elements. Will be empty if this element and none of its children match.
 */
public Elements getElementsByTag(String tagName) {
    Validate.notEmpty(tagName);
    tagName = normalize(tagName);

    return Collector.collect(new Evaluator.Tag(tagName), this);
}
 
Example 15
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find an element by ID, including or under this element.
 * <p>
 * Note that this finds the first matching ID, starting with this element. If you search down from a different
 * starting point, it is possible to find a different element by ID. For unique element by ID within a Document,
 * use {@link Document#getElementById(String)}
 * @param id The ID to search for.
 * @return The first matching element by ID, starting with this element, or null if none found.
 */
public Element getElementById(String id) {
    Validate.notEmpty(id);
    
    Elements elements = Collector.collect(new Evaluator.Id(id), this);
    if (elements.size() > 0)
        return elements.get(0);
    else
        return null;
}
 
Example 16
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have a named attribute set. Case insensitive.
 *
 * @param key name of the attribute, e.g. {@code href}
 * @return elements that have this attribute, empty if none
 */
public Elements getElementsByAttribute(String key) {
    Validate.notEmpty(key);
    key = key.trim();

    return Collector.collect(new Evaluator.Attribute(key), this);
}
 
Example 17
Project: astor   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have an attribute name starting with the supplied prefix. Use {@code data-} to find elements
 * that have HTML5 datasets.
 * @param keyPrefix name prefix of the attribute e.g. {@code data-}
 * @return elements that have attribute names that start with with the prefix, empty if none.
 */
public Elements getElementsByAttributeStarting(String keyPrefix) {
    Validate.notEmpty(keyPrefix);
    keyPrefix = keyPrefix.trim();

    return Collector.collect(new Evaluator.AttributeStarting(keyPrefix), this);
}
 
Example 18
Project: JabRefAutocomplete   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Finds elements, including and recursively under this element, with the specified tag name.
 * @param tagName The tag name to search for (case insensitively).
 * @return a matching unmodifiable list of elements. Will be empty if this element and none of its children match.
 */
public Elements getElementsByTag(String tagName) {
    Validate.notEmpty(tagName);
    tagName = tagName.toLowerCase().trim();

    return Collector.collect(new Evaluator.Tag(tagName), this);
}
 
Example 19
Project: JabRefAutocomplete   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find an element by ID, including or under this element.
 * <p>
 * Note that this finds the first matching ID, starting with this element. If you search down from a different
 * starting point, it is possible to find a different element by ID. For unique element by ID within a Document,
 * use {@link Document#getElementById(String)}
 * @param id The ID to search for.
 * @return The first matching element by ID, starting with this element, or null if none found.
 */
public Element getElementById(String id) {
    Validate.notEmpty(id);
    
    Elements elements = Collector.collect(new Evaluator.Id(id), this);
    if (elements.size() > 0)
        return elements.get(0);
    else
        return null;
}
 
Example 20
Project: JabRefAutocomplete   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have a named attribute set. Case insensitive.
 *
 * @param key name of the attribute, e.g. {@code href}
 * @return elements that have this attribute, empty if none
 */
public Elements getElementsByAttribute(String key) {
    Validate.notEmpty(key);
    key = key.trim().toLowerCase();

    return Collector.collect(new Evaluator.Attribute(key), this);
}
 
Example 21
Project: JabRefAutocomplete   File: Element.java   Source Code and License 5 votes vote down vote up
/**
 * Find elements that have an attribute name starting with the supplied prefix. Use {@code data-} to find elements
 * that have HTML5 datasets.
 * @param keyPrefix name prefix of the attribute e.g. {@code data-}
 * @return elements that have attribute names that start with with the prefix, empty if none.
 */
public Elements getElementsByAttributeStarting(String keyPrefix) {
    Validate.notEmpty(keyPrefix);
    keyPrefix = keyPrefix.trim().toLowerCase();

    return Collector.collect(new Evaluator.AttributeStarting(keyPrefix), this);
}
 
Example 22
Project: xsoup   File: DefaultXPathEvaluator.java   Source Code and License 5 votes vote down vote up
@Override
public XElements evaluate(Element element) {
    Elements elements;
    if (evaluator != null) {
        elements = Collector.collect(evaluator, element);
    } else {
        elements = new Elements();
        elements.add(element);
    }
    return new DefaultXElements(elements, elementOperator);
}
 
Example 23
Project: zongtui-webcrawler   File: DefaultXPathEvaluator.java   Source Code and License 4 votes vote down vote up
@Override
public XElements evaluate(Element element) {
    Elements elements = Collector.collect(evaluator, element);
    return new DefaultXElements(elements, elementOperator);
}
 
Example 24
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have this class, including or under this element. Case insensitive.
 * <p>
 * Elements can have multiple classes (e.g. {@code <div class="header round first">}. This method
 * checks each class, so you can find the above with {@code el.getElementsByClass("header");}.
 * 
 * @param className the name of the class to search for.
 * @return elements with the supplied class name, empty if none
 * @see #hasClass(String)
 * @see #classNames()
 */
public Elements getElementsByClass(String className) {
    Validate.notEmpty(className);

    return Collector.collect(new Evaluator.Class(className), this);
}
 
Example 25
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have an attribute with the specific value. Case insensitive.
 * 
 * @param key name of the attribute
 * @param value value of the attribute
 * @return elements that have this attribute with this value, empty if none
 */
public Elements getElementsByAttributeValue(String key, String value) {
    return Collector.collect(new Evaluator.AttributeWithValue(key, value), this);
}
 
Example 26
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that either do not have this attribute, or have it with a different value. Case insensitive.
 * 
 * @param key name of the attribute
 * @param value value of the attribute
 * @return elements that do not have a matching attribute
 */
public Elements getElementsByAttributeValueNot(String key, String value) {
    return Collector.collect(new Evaluator.AttributeWithValueNot(key, value), this);
}
 
Example 27
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have attributes that start with the value prefix. Case insensitive.
 * 
 * @param key name of the attribute
 * @param valuePrefix start of attribute value
 * @return elements that have attributes that start with the value prefix
 */
public Elements getElementsByAttributeValueStarting(String key, String valuePrefix) {
    return Collector.collect(new Evaluator.AttributeWithValueStarting(key, valuePrefix), this);
}
 
Example 28
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have attributes that end with the value suffix. Case insensitive.
 * 
 * @param key name of the attribute
 * @param valueSuffix end of the attribute value
 * @return elements that have attributes that end with the value suffix
 */
public Elements getElementsByAttributeValueEnding(String key, String valueSuffix) {
    return Collector.collect(new Evaluator.AttributeWithValueEnding(key, valueSuffix), this);
}
 
Example 29
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have attributes whose value contains the match string. Case insensitive.
 * 
 * @param key name of the attribute
 * @param match substring of value to search for
 * @return elements that have attributes containing this text
 */
public Elements getElementsByAttributeValueContaining(String key, String match) {
    return Collector.collect(new Evaluator.AttributeWithValueContaining(key, match), this);
}
 
Example 30
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have attributes whose values match the supplied regular expression.
 * @param key name of the attribute
 * @param pattern compiled regular expression to match against attribute values
 * @return elements that have attributes matching this regular expression
 */
public Elements getElementsByAttributeValueMatching(String key, Pattern pattern) {
    return Collector.collect(new Evaluator.AttributeWithValueMatching(key, pattern), this);
    
}
 
Example 31
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements whose sibling index is less than the supplied index.
 * @param index 0-based index
 * @return elements less than index
 */
public Elements getElementsByIndexLessThan(int index) {
    return Collector.collect(new Evaluator.IndexLessThan(index), this);
}
 
Example 32
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements whose sibling index is greater than the supplied index.
 * @param index 0-based index
 * @return elements greater than index
 */
public Elements getElementsByIndexGreaterThan(int index) {
    return Collector.collect(new Evaluator.IndexGreaterThan(index), this);
}
 
Example 33
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements whose sibling index is equal to the supplied index.
 * @param index 0-based index
 * @return elements equal to index
 */
public Elements getElementsByIndexEquals(int index) {
    return Collector.collect(new Evaluator.IndexEquals(index), this);
}
 
Example 34
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that contain the specified string. The search is case insensitive. The text may appear directly
 * in the element, or in any of its descendants.
 * @param searchText to look for in the element's text
 * @return elements that contain the string, case insensitive.
 * @see Element#text()
 */
public Elements getElementsContainingText(String searchText) {
    return Collector.collect(new Evaluator.ContainsText(searchText), this);
}
 
Example 35
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that directly contain the specified string. The search is case insensitive. The text must appear directly
 * in the element, not in any of its descendants.
 * @param searchText to look for in the element's own text
 * @return elements that contain the string, case insensitive.
 * @see Element#ownText()
 */
public Elements getElementsContainingOwnText(String searchText) {
    return Collector.collect(new Evaluator.ContainsOwnText(searchText), this);
}
 
Example 36
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements whose text matches the supplied regular expression.
 * @param pattern regular expression to match text against
 * @return elements matching the supplied regular expression.
 * @see Element#text()
 */
public Elements getElementsMatchingText(Pattern pattern) {
    return Collector.collect(new Evaluator.Matches(pattern), this);
}
 
Example 37
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements whose own text matches the supplied regular expression.
 * @param pattern regular expression to match text against
 * @return elements matching the supplied regular expression.
 * @see Element#ownText()
 */
public Elements getElementsMatchingOwnText(Pattern pattern) {
    return Collector.collect(new Evaluator.MatchesOwn(pattern), this);
}
 
Example 38
Project: common   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find all elements under this element (including self, and children of children).
 * 
 * @return all elements
 */
public Elements getAllElements() {
    return Collector.collect(new Evaluator.AllElements(), this);
}
 
Example 39
Project: astor   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have this class, including or under this element. Case insensitive.
 * <p>
 * Elements can have multiple classes (e.g. {@code <div class="header round first">}. This method
 * checks each class, so you can find the above with {@code el.getElementsByClass("header");}.
 * 
 * @param className the name of the class to search for.
 * @return elements with the supplied class name, empty if none
 * @see #hasClass(String)
 * @see #classNames()
 */
public Elements getElementsByClass(String className) {
    Validate.notEmpty(className);

    return Collector.collect(new Evaluator.Class(className), this);
}
 
Example 40
Project: astor   File: Element.java   Source Code and License 2 votes vote down vote up
/**
 * Find elements that have an attribute with the specific value. Case insensitive.
 * 
 * @param key name of the attribute
 * @param value value of the attribute
 * @return elements that have this attribute with this value, empty if none
 */
public Elements getElementsByAttributeValue(String key, String value) {
    return Collector.collect(new Evaluator.AttributeWithValue(key, value), this);
}