Java Code Examples for org.jsoup.select.Collector#collect()

The following examples show how to use org.jsoup.select.Collector#collect() . 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: Element.java    From astor with GNU General Public License v2.0 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 2
Source File: Element.java    From astor with GNU General Public License v2.0 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 3
Source File: Element.java    From astor with GNU General Public License v2.0 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 4
Source File: Element.java    From astor with GNU General Public License v2.0 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 5
Source File: Element.java    From astor with GNU General Public License v2.0 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 6
Source File: Element.java    From astor with GNU General Public License v2.0 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 7
Source File: Element.java    From astor with GNU General Public License v2.0 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 8
Source File: Element.java    From astor with GNU General Public License v2.0 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 9
Source File: Element.java    From astor with GNU General Public License v2.0 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 10
Source File: Element.java    From astor with GNU General Public License v2.0 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 11
Source File: Element.java    From astor with GNU General Public License v2.0 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 12
Source File: Element.java    From astor with GNU General Public License v2.0 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 13
Source File: Element.java    From astor with GNU General Public License v2.0 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 14
Source File: Element.java    From astor with GNU General Public License v2.0 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 15
Source File: Element.java    From astor with GNU General Public License v2.0 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 16
Source File: Element.java    From astor with GNU General Public License v2.0 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 17
Source File: Element.java    From astor with GNU General Public License v2.0 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 18
Source File: Element.java    From astor with GNU General Public License v2.0 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 19
Source File: Element.java    From astor with GNU General Public License v2.0 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 20
Source File: Element.java    From astor with GNU General Public License v2.0 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);
}