Docs/API reference

ElementCollection · Node.js

Read, iterate and select from multiple DOM matches.

Download .md
Developers3 min read13 sections
Source reference · Match your SDK version. Availability and known issues
In this guide

Purpose and lifecycle

Node text/html properties return arrays. Python text() concatenates text, while texts() returns a list. Node attr(name) returns one value per match; Python attr(name) reads the first match.

Node indices are zero-based. first()/at() return null when no element exists; Python first()/last()/nth() return None.

Python filter/map run application callbacks in Python. Known issue: iteration over a materialized filtered collection currently exits without yielding its stored items; use texts() or explicit nth() access until corrected.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.

Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.

export class ElementCollection implements Iterable<Element>
typescript1 lines · copy-ready

Usage example

Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.

const links = page.css('a');
for (const link of links) console.log(link.attr('href'));
console.log(links.length, links.text);
typescript3 lines · copy-ready

Members

MemberKindReturn / value typeSource status
constructormethodElementCollectionPresent in source
lengthpropertynumberPresent in source
textpropertystring[]Present in source
htmlpropertystring[]Present in source
attrmethod(string | null)[]Present in source
firstmethodElement | nullPresent in source
atmethodElement | nullPresent in source
[Symbol.iterator]methodIterator<Element, any, any>Present in source

constructor()

Native interop entry point. Applications normally obtain this wrapper from Page.create, a selector or Dataset.build; do not pass a URL or an arbitrary object as a native handle.

Returns / value: ElementCollection.

constructor(inner: JsElementCollection): ElementCollection
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
innerJsElementCollectionRequiredExisting native handle for wrapper interop; not a URL or plain data object.

length

Read the declared value. Its exact type is shown in the signature.

Returns / value: number.

length: number
typescript1 lines · copy-ready

text

Node: array of each match’s text. Python: concatenated text for the collection.

Returns / value: string[].

text: string[]
typescript1 lines · copy-ready

html

Return reconstructed HTML for every match as a Node array.

Returns / value: string[].

html: string[]
typescript1 lines · copy-ready

attr()

Node: array of attribute values or null. Python: attribute of the first match, or None.

Returns / value: (string | null)[].

attr(name: string): (string | null)[]
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
namestringRequiredField, header or attribute name for this operation.

first()

Return the first match, or null/None.

Returns / value: Element | null.

first(): Element | null
typescript1 lines · copy-ready

at()

Return a zero-based match, or null if out of bounds.

Returns / value: Element | null.

at(index: number): Element | null
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
indexnumberRequiredZero-based element index.

[Symbol.iterator]()

Iterate over matched Element wrappers in collection order. See any known limitation above before using a materialized Python collection.

Returns / value: Iterator<Element, any, any>.

[Symbol.iterator](): Iterator<Element>
typescript1 lines · copy-ready

Errors and operational limits

An empty match is valid. Reject negative indices in your Node caller; the native index type is unsigned. Callback exceptions can propagate from Python map/filter.

Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.