Skip to content

API Reference parrot_tools.scraping.toolkit

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.toolkit

View source

WebScrapingToolkit — AbstractToolkit-based entry point for scraping.

Each public async method is automatically exposed as an individual tool for agents and chatbots via AbstractToolkit.

Alias AbstractDriver

Re-exported from parrot_tools.scraping.drivers.abstract.AbstractDriver.

Alias DriverConfig

Re-exported from parrot_tools.scraping.toolkit_models.DriverConfig.

Alias DriverRegistry

Re-exported from parrot_tools.scraping.driver_context.DriverRegistry.

Class ExtractionScore

Heuristic quality score for a ScrapingResult.

Parameter Type Default Description
value float
reasons list[str]
needs_refinement bool

Attributes:

Attribute Type Description
value 0.0 = nothing useful came out, 1.0 = every extract name has rows with fully-populated fields.
reasons Human-readable diagnostic lines (empty rows, null-field rates, step errors). Passed verbatim into the refinement prompt so the LLM knows exactly what to fix.
needs_refinement True if the result is weak enough that a second LLM pass is likely to improve it.

Method ExtractionScore.summary

summary() -> str

Returns: str

Alias PageSnapshot

Re-exported from parrot_tools.scraping.page_snapshot.PageSnapshot.

Alias PathConfinementError

Re-exported from parrot_tools.scraping.confine.PathConfinementError.

Alias PlanGenerator

Re-exported from parrot_tools.scraping.plan_generator.PlanGenerator.

Alias PlanRegistry

Re-exported from parrot_tools.scraping.registry.PlanRegistry.

Alias PlanSaveResult

Re-exported from parrot_tools.scraping.toolkit_models.PlanSaveResult.

Alias PlanSummary

Re-exported from parrot_tools.scraping.toolkit_models.PlanSummary.

Attribute REFINEMENT_TRIGGER_SCORE

Alias ScrapingPlan

Re-exported from parrot_tools.scraping.plan.ScrapingPlan.

Alias ScrapingResult

Re-exported from parrot_tools.scraping.models.ScrapingResult.

Class WebScrapingToolkit

Toolkit for intelligent web scraping and crawling with plan caching.

Inherits from AbstractToolkit so that every public async method is auto-discovered as a tool. Coordinates plan inference (LLM), single-page scraping, multi-page crawling, and plan persistence.

Parameter Type Default Description
driver_type Literal['selenium', 'playwright', 'obscura'] 'playwright' Browser driver backend to use.
browser Literal['chrome', 'firefox', 'edge', 'safari', 'undetected', 'webkit'] 'chrome' Browser to launch.
headless bool True Run headless.
session_based bool False Reuse driver across calls (sequential only).
mobile bool False Enable mobile emulation.
mobile_device str | None None Specific mobile device name.
auto_install bool True Auto-install/update browser driver.
default_timeout int 10 Default timeout in seconds.
retry_attempts int 3 Retries for failed operations.
delay_between_actions float 1.0 Seconds between plan steps.
overlay_housekeeping bool True Dismiss overlays between actions.
disable_images bool False Block image loading.
custom_user_agent str | None None Override user agent.
browser_binary str | None None Browser executable to launch (Playwright executable_path / Selenium binary_location). For Chrome-family browsers it defaults to the DEFAULT_CHROME_EXECUTABLE_PATH setting.
plans_dir str | Path | None None Root directory for plan storage.
llm_client Any | None None LLM client with async complete(prompt) -> str.
cdp_endpoint_url str | None None Explicit Obscura CDP endpoint (FEAT-530). Only used when driver_type="obscura".
obscura_binary str | None None Path to (or PATH-resolvable name of) the Obscura binary. Only used when driver_type="obscura".
obscura_port int 9222 CDP port of the supervised Obscura process.
obscura_stealth bool False Obscura stealth-mode flag.
obscura_allow_private_network bool False Obscura --allow-private-network flag.
confine_paths bool False
record_video bool False Record Playwright sessions under files_root/recordings.
**kwargs Any {} Passed through to AbstractToolkit.

Attributes:

Attribute Type Description
llm_dependent_tools frozenset
files_root Path Where the actions of a confined toolkit may read and write files: <plans_dir>/files.

Method WebScrapingToolkit.start

Initialise session driver when session_based=True.

In session mode a single AbstractDriver instance is created and reused across all scrape() / crawl() calls until stop() is invoked. The concrete driver type (Selenium or Playwright) is determined by DriverConfig.driver_type.

.. note:: Session mode is for sequential use only.

start() -> None

Method WebScrapingToolkit.stop

Shut down the session driver if active.

stop() -> None

Method WebScrapingToolkit.plan_create

Create a scraping plan for a URL via LLM or cache.

Returns a cached plan if one exists for the URL (unless force_regenerate=True), otherwise generates a new one via the configured LLM client. When neither snapshot is supplied nor auto_snapshot disabled, the page is fetched via aiohttp and summarized for the LLM so it can pick real selectors.

plan_create(url: str, objective: str, hints: dict[str, Any] | None = None, force_regenerate: bool = False, snapshot: PageSnapshot | None = None, auto_snapshot: bool = True) -> ScrapingPlan

Parameter Type Default Description
url str Target URL.
objective str What to extract.
hints dict[str, Any] | None None Optional hints for the LLM (e.g. auth_required, pagination).
force_regenerate bool False Bypass cache and always call the LLM.
snapshot PageSnapshot | None None Pre-built PageSnapshot (e.g. captured via the browser driver for JS-rendered pages). Skips auto-fetch.
auto_snapshot bool True If True, fetch a snapshot via aiohttp when one is not supplied. Disable for offline plan generation or when the page is not reachable without a browser.

Returns: ScrapingPlan — A ScrapingPlan ready for execution.

Method WebScrapingToolkit.plan_save

Save a scraping plan to disk and register it.

plan_save(plan: ScrapingPlan, overwrite: bool = False) -> PlanSaveResult

Parameter Type Default Description
plan ScrapingPlan Plan to save.
overwrite bool False Replace an existing file if it exists.

Returns: PlanSaveResult — PlanSaveResult with save status and file path.

Method WebScrapingToolkit.plan_load

Load a plan by URL (registry lookup) or by name.

plan_load(url_or_name: str) -> ScrapingPlan | None

Parameter Type Default Description
url_or_name str A URL to look up or a plan name.

Returns: ScrapingPlan | None — The loaded ScrapingPlan or None if not found.

Method WebScrapingToolkit.plan_list

List registered plans with optional filtering.

plan_list(domain_filter: str | None = None, tag_filter: str | None = None) -> list[PlanSummary]

Parameter Type Default Description
domain_filter str | None None Only include plans matching this domain.
tag_filter str | None None Only include plans containing this tag.

Returns: list[PlanSummary] — List of PlanSummary objects.

Method WebScrapingToolkit.plan_delete

Delete a plan from the registry and optionally from disk.

plan_delete(name: str, delete_file: bool = True) -> bool

Parameter Type Default Description
name str Plan name to delete.
delete_file bool True Also remove the plan file from disk.

Returns: bool — True if the plan was found and removed.

Method WebScrapingToolkit.scrape

Scrape a single page using a plan, raw steps, or auto-generation.

Plan resolution priority (when steps is not provided):

  1. Explicit plan argument
  2. Registry cache lookup by url
  3. Auto-generate via LLM if objective is provided
  4. Raise ValueError

When steps is provided, they are executed directly without plan resolution.

Refinement loop: when an objective is supplied and the initial plan's extraction quality scores below REFINEMENT_TRIGGER_SCORE (empty rows, mostly-null fields, or step errors), we capture a fresh post-execution DOM snapshot and ask the LLM to produce a revised plan, then re-execute. Controlled by max_refinement_attempts (default 1 — so at most 2 LLM calls total). Disabled when the plan came from cache/explicit input, since we don't own that plan to refine it.

scrape(url: str, plan: ScrapingPlan | dict[str, Any] | None = None, objective: str | None = None, steps: list[dict[str, Any]] | None = None, selectors: list[dict[str, Any]] | None = None, save_plan: bool = False, browser_config_override: dict[str, Any] | None = None, max_refinement_attempts: int = 1) -> ScrapingResult

Parameter Type Default Description
url str Target URL.
plan ScrapingPlan | dict[str, Any] | None None Explicit ScrapingPlan or dict.
objective str | None None Scraping objective (for auto-generation).
steps list[dict[str, Any]] | None None Raw steps list for ad-hoc execution (bypasses plan resolution).
selectors list[dict[str, Any]] | None None Content extraction selectors (used with raw steps).
save_plan bool False Save the resolved/generated plan after scraping.
browser_config_override dict[str, Any] | None None Per-call driver config overrides.
max_refinement_attempts int 1 How many LLM refinement passes to allow when the first extraction scores poorly. Set to 0 to disable. Default 1.

Returns: ScrapingResult — ScrapingResult with extracted data and metadata. When refinement ran, returns the result of the FINAL pass (not the initial one), regardless of whether it scored higher.

Method WebScrapingToolkit.crawl

Crawl multiple pages starting from a URL.

Delegates to CrawlEngine (FEAT-013). If the engine is not available, raises NotImplementedError.

crawl(start_url: str, depth: int = 1, max_pages: int | None = None, follow_selector: str | None = None, follow_pattern: str | None = None, plan: ScrapingPlan | dict[str, Any] | None = None, objective: str | None = None, save_plan: bool = False, concurrency: int = 1) -> Any

Parameter Type Default Description
start_url str Entry point URL.
depth int 1 Maximum crawl depth.
max_pages int | None None Maximum number of pages to visit.
follow_selector str | None None CSS selector for links to follow.
follow_pattern str | None None URL regex pattern for links to follow.
plan ScrapingPlan | dict[str, Any] | None None Explicit scraping plan for each page.
objective str | None None Scraping objective for auto-generation.
save_plan bool False Persist the plan after first scrape.
concurrency int 1 Number of concurrent page fetches.

Returns: Any — CrawlResult from the engine.

Raises:

  • NotImplementedError — If CrawlEngine is not available.

Alias confine_to_files_root

Re-exported from parrot_tools.scraping.confine.confine_to_files_root.

Alias driver_context

Re-exported from parrot_tools.scraping.driver_context.driver_context.

Alias execute_plan_steps

Re-exported from parrot_tools.scraping.executor.execute_plan_steps.

Alias is_within

Re-exported from parrot_tools.scraping.plan_io.is_within.

Alias load_plan_from_disk

Re-exported from parrot_tools.scraping.plan_io.load_plan_from_disk.

Attribute logger

Alias save_plan_to_disk

Re-exported from parrot_tools.scraping.plan_io.save_plan_to_disk.

Alias snapshot_from_driver

Re-exported from parrot_tools.scraping.page_snapshot.snapshot_from_driver.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally