Docs/API reference

Element · Python

Read one selected DOM element and its attributes.

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

Purpose and lifecycle

Obtain elements from a Page collection rather than constructing wrappers around native handles yourself.

Node uses text and html properties. Python uses text() and html() methods and exposes additional traversal helpers. Python Element is available through crawlingo.element and as a collection result, not as a top-level import.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Reachable result/callback type; not a top-level 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.

class Element
python1 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.

heading = page.css("h1").first()
if heading is not None:
    print(heading.text(), heading.attr("id"))
python3 lines · copy-ready

Members

MemberKindReturn / value typeSource status
__init__methodNot annotated; see behavior notesPresent in source
textmethodstrPresent in source
htmlmethodstrPresent in source
attrmethodstrPresent in source
attrsmethoddictPresent in source
parentmethod'Element'Present in source
childrenmethod'ElementCollection'Present in source
nextmethod'Element'Present in source
prevmethod'Element'Present in source
siblingsmethod'ElementCollection'Present in source
__repr__methodstrPresent in source

__init__()

Wrap a native DOM element and optional extraction hooks. Normally obtained through Page selectors and collection access.

Returns / value: Not annotated; see behavior notes.

def __init__(self, core_element: _CoreElement, after_extract_hooks: List[Callable]=None)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
core_element_CoreElementRequiredNative DOM element handle.
after_extract_hooksList[Callable]Default: NonePython string callbacks applied after text extraction. Empty return values retain the previous string.

text()

Read descendant text in document order. Python after-extract hooks apply to this value.

Returns / value: str.

def text(self) -> str
python1 lines · copy-ready

html()

Read the reconstructed outer HTML for the selected node.

Returns / value: str.

def html(self) -> str
python1 lines · copy-ready

attr()

Look up one attribute by name. Missing values return null in Node or None in Python.

Returns / value: str.

def attr(self, name: str) -> str
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
namestrRequiredField, header or attribute name for this operation.

attrs()

Return all attributes as a dictionary.

Returns / value: dict.

def attrs(self) -> dict
python1 lines · copy-ready

parent()

Return the parent element, or None when absent.

Returns / value: 'Element'.

def parent(self) -> 'Element'
python1 lines · copy-ready

children()

Return the child-element collection.

Returns / value: 'ElementCollection'.

def children(self) -> 'ElementCollection'
python1 lines · copy-ready

next()

Return the next sibling, or None.

Returns / value: 'Element'.

def next(self) -> 'Element'
python1 lines · copy-ready

prev()

Return the previous sibling, or None.

Returns / value: 'Element'.

def prev(self) -> 'Element'
python1 lines · copy-ready

siblings()

Return sibling elements as a collection.

Returns / value: 'ElementCollection'.

def siblings(self) -> 'ElementCollection'
python1 lines · copy-ready

__repr__()

Return a short debugging representation of the wrapper. This is not a data export or a stable serialization format.

Returns / value: str.

def __repr__(self) -> str
python1 lines · copy-ready

Errors and operational limits

Absent attributes and absent relatives may return null/None even where a Python annotation is narrower. Node exposes only text, html and attr; do not translate Python traversal calls directly.

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.