Page · Python
Fetch one page and inspect its parsed HTML before defining a dataset schema.
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 PageUsage 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())Members
| Member | Kind | Return / value type | Source status |
|---|---|---|---|
| create | static method | 'Page' | Present in source |
| __init__ | method | Not annotated; see behavior notes | Present in source |
| url | property | str | Present in source |
| status | property | int | Present in source |
| html | method | str | Present in source |
| title | method | str | Present in source |
| css | method | ElementCollection | Present in source |
| xpath | method | ElementCollection | Present in source |
| find_text | method | ElementCollection | Present in source |
| after_text | method | ElementCollection | Present in source |
| before_text | method | ElementCollection | Present in source |
| regex | method | ElementCollection | Present in source |
| before_fetch | method | 'Page' | Present in source |
| after_fetch | method | 'Page' | Present in source |
| before_parse | method | 'Page' | Known limitation — read entry |
| after_extract | method | '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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| url | str | Required | HTTP(S) source URL; verify the target is appropriate for your application. |
| auto_match | bool | Default: False | Heuristic recovery option; read Page and Dataset behavior because their native paths differ. |
| timeout | int | Default: 30 | Per-attempt timeout in whole seconds; retries and pacing add elapsed time. |
| retries | int | Default: 3 | Additional request attempts after the initial one. |
| headers | dict | Default: None | Header names and values; avoid sharing credentials across unrelated sites. |
| cookies | dict | Default: None | Explicit cookie-name/value defaults. |
| proxy | str | Default: None | Per-request proxy URL; overrides the relevant session default. |
| session | Optional['Session'] | Default: None | Shared 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)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| url | str | Required | HTTP(S) source URL; verify the target is appropriate for your application. |
| auto_match | bool | Default: False | Heuristic recovery option; read Page and Dataset behavior because their native paths differ. |
| timeout | int | Default: 30 | Per-attempt timeout in whole seconds; retries and pacing add elapsed time. |
| retries | int | Default: 3 | Additional request attempts after the initial one. |
| headers | dict | Default: None | Header names and values; avoid sharing credentials across unrelated sites. |
| cookies | dict | Default: None | Explicit cookie-name/value defaults. |
| proxy | str | Default: None | Per-request proxy URL; overrides the relevant session default. |
| session | Optional['Session'] | Default: None | Shared 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) -> strstatus
HTTP response status code.
Returns / value: int.
def status(self) -> inthtml()
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) -> strtitle()
Return the text of the title element, or an empty string when absent.
Returns / value: str.
def title(self) -> strcss()
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| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| selector | str | Required | Selector 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| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| query | str | Required | Supported 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| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| text | str | Required | Text 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| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| text | str | Required | Text anchor used for matching. |
before_text()
Select the element before a matching text anchor.
Returns / value: ElementCollection.
def before_text(self, text: str) -> ElementCollection| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| text | str | Required | Text 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| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| pattern | str | Required | Rust 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Not annotated | Required | Application 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Not annotated | Required | Application 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Not annotated | Required | Application 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Not annotated | Required | Application 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.