Element · Python
Read one selected DOM element and its attributes.
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 ElementUsage 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"))Members
| Member | Kind | Return / value type | Source status |
|---|---|---|---|
| __init__ | method | Not annotated; see behavior notes | Present in source |
| text | method | str | Present in source |
| html | method | str | Present in source |
| attr | method | str | Present in source |
| attrs | method | dict | Present in source |
| parent | method | 'Element' | Present in source |
| children | method | 'ElementCollection' | Present in source |
| next | method | 'Element' | Present in source |
| prev | method | 'Element' | Present in source |
| siblings | method | 'ElementCollection' | Present in source |
| __repr__ | method | str | Present 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)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| core_element | _CoreElement | Required | Native DOM element handle. |
| after_extract_hooks | List[Callable] | Default: None | Python 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) -> strhtml()
Read the reconstructed outer HTML for the selected node.
Returns / value: str.
def html(self) -> strattr()
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| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| name | str | Required | Field, header or attribute name for this operation. |
attrs()
Return all attributes as a dictionary.
Returns / value: dict.
def attrs(self) -> dictparent()
Return the parent element, or None when absent.
Returns / value: 'Element'.
def parent(self) -> 'Element'children()
Return the child-element collection.
Returns / value: 'ElementCollection'.
def children(self) -> 'ElementCollection'next()
Return the next sibling, or None.
Returns / value: 'Element'.
def next(self) -> 'Element'prev()
Return the previous sibling, or None.
Returns / value: 'Element'.
def prev(self) -> 'Element'siblings()
Return sibling elements as a collection.
Returns / value: 'ElementCollection'.
def siblings(self) -> 'ElementCollection'__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) -> strErrors 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.