Skip to main content
Version: Next

PydanticAiCrawlingContext

The crawling context used by the PydanticAiCrawler.

It extends ParselCrawlingContext, so the full Parsel selector (and enqueue_links) remain available alongside the AI-powered extract helper. Handlers can mix cheap manual selectors with AI extraction on the same page.

Hierarchy

Index

Methods

__hash__

  • __hash__(): int

create_modified_copy

  • create_modified_copy(push_data, add_requests, get_key_value_store): Self
  • Create a modified copy of the crawling context with specified changes.


    Parameters

    • optionalpush_data: PushDataFunction | None = None
    • optionaladd_requests: AddRequestsFunction | None = None
    • optionalget_key_value_store: GetKeyValueStoreFromRequestHandlerFunction | None = None

    Returns Self

extract_form_requests

  • async extract_form_requests(*, selector, fields, click, all_forms, kwargs): list[Request]
  • Create requests submitting the forms matching selector the way a browser does.

    By default, only one form is submitted: the first one a browser can submit among those sharing the most field names with fields.


    Parameters

    • optionalkeyword-onlyselector: str = 'form'

      CSS selector for the forms. An invalid one matches no form.

    • optionalkeyword-onlyfields: Mapping[str, str | Sequence[str] | None] | None = None

      Values replacing the form fields or adding new ones. A None value drops the field and a sequence submits it once per value. With all_forms, only the fields a form has are replaced.

    • optionalkeyword-onlyclick: bool | Mapping[str, str] = True

      The submit button to click: True for the first enabled one, if any, False for none, or a mapping of attributes the button must have, disabled or not, which skips forms without such a button.

    • optionalkeyword-onlyall_forms: bool = False

      Submit each matching form instead of only one.

    • kwargs: Unpack[FormRequestOptions]

    Returns list[Request]

from_basic_crawling_context

  • from_basic_crawling_context(context, http_response): Self

from_http_crawling_context

  • from_http_crawling_context(context, parsed_content, enqueue_links, extract_links): Self

from_parsed_http_crawling_context

  • from_parsed_http_crawling_context(context): Self

from_parsel_crawling_context

  • from_parsel_crawling_context(context, *, extract, ai_usage): Self

get_snapshot

html_to_text

  • html_to_text(): str

Properties

add_requests

add_requests: AddRequestsFunction

Add requests crawling context helper function.

ai_usage

The cumulative token usage stats of the extractor across calls in this crawl.

enqueue_links

enqueue_links: EnqueueLinksFunction

extract

Extract a structured Pydantic model from the page using the configured AI extractor.

extract_links

extract_links: ExtractLinksFunction

get_key_value_store

Get key-value store crawling context helper function.

http_response

http_response: HttpResponse

The HTTP response received from the server.

log

log: logging.Logger

Logger instance.

parsed_content

parsed_content: TParseResult

proxy_info

proxy_info: ProxyInfo | None

Proxy information for the current page being processed.

push_data

push_data: PushDataFunction

Push data crawling context helper function.

register_deferred_cleanup

register_deferred_cleanup: Callable[[DeferredCleanupCallback], None]

Register an async callback to be called after request processing completes (including error handlers).

request

request: Request

Request object for the current page being processed.

selector

selector: Selector

Convenience alias.

send_request

send_request: SendRequestFunction

Send request crawling context helper function.

session

session: Session | None

Session object for the current page being processed.

use_state

use_state: UseStateFunction

Use state crawling context helper function.