Docs/API reference

Page · Python

Fetch one page and inspect its parsed HTML before defining a dataset schema.

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

Purpose and lifecycle

Python Page(url) is lazy; reading status, html or selectors triggers loading. Python Page.create fetches immediately. Node Page.create returns a promise; the Node constructor accepts an existing native page.

A page retains HTML and a DOM tree. Use DatasetJob for large inputs rather than keeping a list of Page objects.

HTTP statuses such as 404, 429 and 500 are returned through status, including after retries are exhausted. They do not automatically become typed HTTP exceptions.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. 1 member(s) have a known limitation; see the marked entries below.

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

from crawlingo import Page

page = Page.create("https://example.com/", timeout=30, retries=1)
print(page.status, page.title())
print(page.css("h1").texts())
python5 lines · copy-ready

Members

MemberKindReturn / value typeSource status
createstatic method'Page'Present in source
__init__methodNot annotated; see behavior notesPresent in source
urlpropertystrPresent in source
statuspropertyintPresent in source
htmlmethodstrPresent in source
titlemethodstrPresent in source
cssmethodElementCollectionPresent in source
xpathmethodElementCollectionPresent in source
find_textmethodElementCollectionPresent in source
after_textmethodElementCollectionPresent in source
before_textmethodElementCollectionPresent in source
regexmethodElementCollectionPresent in source
before_fetchmethod'Page'Present in source
after_fetchmethod'Page'Present in source
before_parsemethod'Page'Known limitation — read entry
after_extractmethod'Page'Present in source

create()

Fetch and parse the URL. Node request headers/cookies merge over the session defaults; explicit timeout, proxy and profile take precedence. Python passes its Page defaults to native code, including 30 seconds and 3 retries.

Returns / value: 'Page'.

def create(cls, url: str, auto_match: bool=False, timeout: int=30, retries: int=3, headers: dict=None, cookies: dict=None, proxy: str=None, session: Optional['Session']=None) -> 'Page'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstrRequiredHTTP(S) source URL; verify the target is appropriate for your application.
auto_matchboolDefault: FalseHeuristic recovery option; read Page and Dataset behavior because their native paths differ.
timeoutintDefault: 30Per-attempt timeout in whole seconds; retries and pacing add elapsed time.
retriesintDefault: 3Additional request attempts after the initial one.
headersdictDefault: NoneHeader names and values; avoid sharing credentials across unrelated sites.
cookiesdictDefault: NoneExplicit cookie-name/value defaults.
proxystrDefault: NonePer-request proxy URL; overrides the relevant session default.
sessionOptional['Session']Default: NoneShared request state. Omit only where the signature provides a default.

__init__()

Create a lazy Python Page. Network access starts on create() or the first content/status/selector operation. Register hooks before triggering that load.

Returns / value: Not annotated; see behavior notes.

def __init__(self, url: str, auto_match: bool=False, timeout: int=30, retries: int=3, headers: dict=None, cookies: dict=None, proxy: str=None, session: Optional['Session']=None)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstrRequiredHTTP(S) source URL; verify the target is appropriate for your application.
auto_matchboolDefault: FalseHeuristic recovery option; read Page and Dataset behavior because their native paths differ.
timeoutintDefault: 30Per-attempt timeout in whole seconds; retries and pacing add elapsed time.
retriesintDefault: 3Additional request attempts after the initial one.
headersdictDefault: NoneHeader names and values; avoid sharing credentials across unrelated sites.
cookiesdictDefault: NoneExplicit cookie-name/value defaults.
proxystrDefault: NonePer-request proxy URL; overrides the relevant session default.
sessionOptional['Session']Default: NoneShared request state. Omit only where the signature provides a default.

url

Source/final URL according to the operation; check redirects and provenance needs.

Returns / value: str.

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

status

HTTP response status code.

Returns / value: int.

def status(self) -> int
python1 lines · copy-ready

html()

Load the page if necessary and return its HTML string. Inspect status separately; an HTTP error response can still have a body.

Returns / value: str.

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

title()

Return the text of the title element, or an empty string when absent.

Returns / value: str.

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

css()

Evaluate the supported CSS subset and return a collection in document order. This is not a browser querySelectorAll implementation.

Returns / value: ElementCollection.

def css(self, selector: str) -> ElementCollection
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
selectorstrRequiredSelector evaluated against the fetched DOM.

xpath()

Evaluate the supported basic XPath subset; advanced XPath axes/functions are not implemented.

Returns / value: ElementCollection.

def xpath(self, query: str) -> ElementCollection
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
querystrRequiredSupported XPath expression.

find_text()

Find DOM nodes by text content using the engine text selector.

Returns / value: ElementCollection.

def find_text(self, text: str) -> ElementCollection
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
textstrRequiredText anchor used for matching.

after_text()

Select the element after a matching text anchor; inspect sample output before relying on a repeated label.

Returns / value: ElementCollection.

def after_text(self, text: str) -> ElementCollection
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
textstrRequiredText anchor used for matching.

before_text()

Select the element before a matching text anchor.

Returns / value: ElementCollection.

def before_text(self, text: str) -> ElementCollection
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
textstrRequiredText anchor used for matching.

regex()

Compile the Rust regular expression and match text. Invalid syntax produces SelectorError. Rust regex does not support look-around or backreferences.

Returns / value: ElementCollection.

def regex(self, pattern: str) -> ElementCollection
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
patternstrRequiredRust regular expression.

before_fetch()

Register a Python hook before lazy loading. Mutating the shared headers dictionary affects request headers; assigning a new context URL does not change the Page URL used to fetch.

Returns / value: 'Page'.

def before_fetch(self, fn) -> 'Page'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnNot annotatedRequiredApplication callback invoked with the documented value or event.

after_fetch()

Register a Python callback receiving a response context with status. It runs after the native fetch and parse have completed.

Returns / value: 'Page'.

def after_fetch(self, fn) -> 'Page'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnNot annotatedRequiredApplication callback invoked with the documented value or event.

before_parse()

Known limitation: The callback runs after native parsing and its returned HTML is discarded. It does not modify the DOM.

Known limitation: this hook runs after the native DOM has already been parsed. Returned replacement HTML is not fed back into the parser; it cannot transform the parsed DOM.

Returns / value: 'Page'.

def before_parse(self, fn) -> 'Page'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnNot annotatedRequiredApplication callback invoked with the documented value or event.

after_extract()

Apply Python transforms to extracted text. A falsy hook return currently keeps the previous value, so returning an empty string does not erase it.

Returns / value: 'Page'.

def after_extract(self, fn) -> 'Page'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnNot annotatedRequiredApplication callback invoked with the documented value or event.

Errors and operational limits

Network failures reject/raise. Node maps native timeout, DNS and regex selector failures to typed errors. Missing selector matches return an empty collection. Python exception conversion is message-based.

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.