findNextSiblings method
- String name, {
- String? id,
- String? class_,
- Map<
String, Object> ? attrs, - Pattern? regex,
- Pattern? string,
- String? selector,
- int? limit,
These methods use nextSiblings to iterate over the rest of an element’s siblings in the tree.
The findNextSiblings method returns all the siblings that match, and findNextSibling only returns the first one.
Filters:
- name
, the tag name, use asterisk (*) to search any tag.
- class_
, search by CSS class. Remember that a single tag can have
multiple values for its “class” attribute. When you search for a tag
that matches a certain CSS class, you’re matching against
any of its CSS classes.
For example for HTML '<p class="body strikeout"></p>'
-
class_: 'body'
... matches -
class_: 'body strikeout'
... matches -
class_: 'strikeout body'
... does not match (different order)
- id
, search by 'id' attribute.
- attrs
, for specifying the attributes of a tag, where key is
name of the attribute and value is the value of the attribute
(the only allowed types of the value are String or bool).
Use true
as value of an attribute to search for any attribute values.
- regex
, search for element names, via Pattern.
For example: regex: r'^b'
... will search for <b>, <body>, etc. elements.
- string
, search for strings (text) inside of elements, via Pattern.
For example: string: r'^Article #\d*'
- limit
, to take only a certain number of results.
You can provide your own CSS selector
selector
, if it is specified then both name
and attrs
will be ignored. If such selector is not implemented this method
will throw UnimplementedError.
Use true
as an attribute value to search any value.
Implementation
@override
List<Bs4Element> findNextSiblings(
String name, {
String? id,
String? class_,
Map<String, Object>? attrs,
Pattern? regex,
Pattern? string,
String? selector,
int? limit,
}) {
assert(limit == null || limit >= 0);
final matched = <Bs4Element>[];
final bs4 = _bs4;
final bs4NextSiblings = bs4.nextSiblings;
if (bs4NextSiblings.isEmpty) return matched;
final topElement = _getTopElement(bs4);
final allResults = _getAllResults(
topElement: topElement,
name: name,
class_: class_,
id: id,
attrs: attrs,
regex: regex,
string: string,
selector: selector,
);
final filtered = _findMatches(allResults, bs4NextSiblings);
matched.addAll(filtered);
return _limitedList(matched, limit);
}