Docs/API reference

Dataset · Node.js

Extract named fields from one page, with optional validation and small-result exports.

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

Purpose and lifecycle

field adds a named selector; build fetches once and returns DatasetResult. This API keeps results in memory.

buildStructured/extractStructured zip selector results by their positions. Missing values can change row alignment. Prefer DatasetJob with row_selector for reliable repeated records.

The Python wrapper exposes transform callbacks for ordinary build/build_async. The Node field options expose extractType. Do not infer parity from the underlying Rust field type.

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 Dataset
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.

import { Dataset } from 'crawlingo';
const result = await new Dataset('https://example.com/')
  .field('title', 'h1').build();
console.log(result.toDict());
await result.toJson('page.json');
typescript5 lines · copy-ready

Members

MemberKindReturn / value typeSource status
constructormethodDatasetPresent in source
fieldmethodthisPresent in source
withSchemamethodthisPresent in source
autoMatchmethodthisPresent in source
timeoutmethodthisPresent in source
headersmethodthisPresent in source
buildmethodPromise<DatasetResult>Present in source
extractStructuredmethodRecord<string, string>[]Present in source
buildStructuredmethodPromise<Record<string, string>[]>Present in source
saveJsonstatic methodvoidPresent in source
saveCsvstatic methodvoidPresent in source

constructor()

Configure extraction for one URL with the supplied or default session. Add fields, then call build to fetch and produce a result.

Returns / value: Dataset.

constructor(url: string, session?: Session): Dataset
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstringRequiredHTTP(S) source URL; verify the target is appropriate for your application.
sessionSession | undefinedOptionalShared request state. Omit only where the signature provides a default.

field()

Append a field definition. name is its output key; selector_type/selectorType chooses the selector family; default/defaultVal supplies a fallback when empty. Node extractType supports text, price, datetime, url and attr:name.

Returns / value: this.

field(name: string, selector: string, options?: { selectorType?: "css" | "xpath" | "regex" | "text" | "after_text" | "before_text"; defaultVal?: string; extractType?: string; }): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
namestringRequiredField, header or attribute name for this operation.
selectorstringRequiredSelector evaluated against the fetched DOM.
options{ selectorType?: "css" | "xpath" | "regex" | "text" | "after_text" | "before_text"; defaultVal?: string; extractType?: string; } | undefinedOptionalOptional settings object. Its inline signature lists the accepted keys and types.

withSchema()

Attach DatasetSchema to validate/coerce the collected field map before returning it.

Returns / value: this.

withSchema(schema: DatasetSchema): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
schemaDatasetSchemaRequiredDatasetSchema containing validation constraints.

autoMatch()

Set heuristic recovery on the attached session for ordinary Dataset extraction.

Returns / value: this.

autoMatch(enabled: boolean): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
enabledbooleanRequiredEnable or disable this behavior.

timeout()

Set timeout on the attached session in seconds.

Returns / value: this.

timeout(seconds: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
secondsnumberRequiredTime in seconds; see the method-specific range and timing semantics.

headers()

Replace headers on the attached session.

Returns / value: this.

headers(headers: Record<string, string>): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
headersRecord<string, string>RequiredHeader names and values; avoid sharing credentials across unrelated sites.

build()

Fetch, parse and extract one field map. Node returns Promise<DatasetResult>; Python blocks and returns DatasetResult.

Returns / value: Promise<DatasetResult>.

build(): Promise<DatasetResult>
typescript1 lines · copy-ready

extractStructured()

Extract positional rows from an already parsed Page without making another fetch.

Returns / value: Record<string, string>[].

extractStructured(page: Page | JsPage): Array<Record<string, string>>
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
pagePage | JsPageRequiredPage object to extract from; distinct from a page-number pagination parameter.

buildStructured()

Fetch the configured URL and return positional multi-row records in memory.

Returns / value: Promise<Record<string, string>[]>.

buildStructured(): Promise<Array<Record<string, string>>>
typescript1 lines · copy-ready

saveJson()

Write the supplied records as a JSON array. The destination file is created or replaced.

Returns / value: void.

saveJson(records: Array<Record<string, string>>, path: string): void
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
recordsRecord<string, string>[]RequiredIn-memory row maps to export.
pathstringRequiredFilesystem path relative to the process working directory unless absolute.

saveCsv()

Write a CSV header and the supplied records. The destination file is created or replaced. Use a consistent record schema.

Returns / value: void.

saveCsv(records: Array<Record<string, string>>, path: string): void
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
recordsRecord<string, string>[]RequiredIn-memory row maps to export.
pathstringRequiredFilesystem path relative to the process working directory unless absolute.

Errors and operational limits

Non-success HTTP statuses abort a Dataset build. Required schema violations, regex syntax errors, fingerprint storage failures and export errors can fail the operation. Node uses the typed error bridge; Python uses its wrapper-specific conversion.

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.