Skip to content

Documentation

TypeScript SDK: Node: a page element

Dom.q() returns one element or null; Dom.qa() returns an array. Check for a missing element before reading it.

Each example is a separate fragment inside async function run(ctx: Akmelo.Context): Promise<void>. Use await only for methods whose signature returns a Promise.

Obtaining the object

const node = ctx.dom('<a href="/product">Product</a>', 'https://example.com').q('a');
if (!node) return;

Methods

text

node.text(trim) → string

Get the found element's text. Repeated spaces and line breaks are combined.

const result = node.text();

html

node.html() → string

Get the whole element's HTML, including its own tag.

const result = node.html();

attr

node.attr(name) → string | null

Get the value of one attribute.

const result = node.attr('href');

abs

node.abs(attribute) → string | null

Get an absolute URL from an attribute. href is used by default.

const result = node.abs('href');

q

node.q(css) → Node | null

Find the first matching element inside the current fragment.

const result = node.q('.price');

qa

node.qa(css) → Array<Node>

Get all matches inside the current fragment.

const result = node.qa('a');

exists

node.exists() → boolean

Check that an obtained Node exists.

const result = node.exists();