Skip to content

API Reference parrot_loaders.webscraping

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

parrot_loaders.webscraping

View source

WebScrapingLoader — Loader interface for WebScrapingToolkit + CrawlEngine.

Bridges parrot's Loader abstraction with the scraping/crawling infrastructure in parrot_tools.scraping, converting ScrapingResult / CrawlResult into chunked Document objects suitable for vector stores and PageIndex.

Single-page usage::

loader = WebScrapingLoader(
    source="https://example.com/docs",
    selectors=[
        {"name": "content", "selector": "article.main", "extract_type": "text"},
        {"name": "title", "selector": "h1", "extract_type": "text"},
    ],
    tags=["p", "h1", "h2", "h3", "article", "section"],
)
docs = await loader.load()

Crawl usage::

loader = WebScrapingLoader(
    source="https://example.com/docs",
    crawl=True,
    depth=2,
    max_pages=50,
    follow_pattern=r"/docs/.*",
)
docs = await loader.load()

With a ScrapingPlan::

from parrot_tools.scraping.plan import ScrapingPlan
plan = ScrapingPlan(url="https://example.com", objective="Extract docs", steps=[...])
loader = WebScrapingLoader(source="https://example.com", plan=plan)
docs = await loader.load()

Attribute HAS_TRAFILATURA

Class WebScrapingLoader

Load web pages via WebScrapingToolkit and convert to Documents.

Delegates browser automation and crawling to the scraping infrastructure (parrot_tools.scraping) while exposing the standard Loader interface (_load / load).

Parameter Type Default Description
source Optional[Union[str, List[str]]] None URL or list of URLs to scrape.
selectors Optional[List[Dict[str, Any]]] None CSS/XPath selectors for structured extraction. Each dict has keys: name, selector, and optionally selector_type (css|xpath|tag), extract_type (text|html|attribute), attribute, multiple.
tags Optional[List[str]] None HTML tags to extract text as independent fragment documents (e.g. ['p', 'h1', 'article']). Opt-in: defaults to an empty list because per-tag fragments often produce sub-chunks smaller than min_chunk_size (e.g. a lone <h2>Frequently asked questions</h2> becomes a 4-token "chunk" after the splitter, polluting vector stores with noise). When needed, pass an explicit list; an empty list disables fragment emission. The full-page markdown/trafilatura document is always emitted and will be chunked coherently by the splitter.
steps Optional[List[Dict[str, Any]]] None Raw scraping steps for browser automation (navigate, click, etc.). If omitted, a simple navigate step is generated from the URL.
plan Optional[Any] None An explicit ScrapingPlan for advanced scenarios.
objective Optional[str] None Scraping objective string — triggers LLM plan auto-generation when no explicit plan or steps are provided.
crawl bool False Enable multi-page crawling via CrawlEngine.
depth int 1 Maximum crawl depth (0 = only the start URL).
max_pages Optional[int] None Hard cap on total pages scraped during a crawl.
follow_selector Optional[str] None CSS selector for links to follow during crawling.
follow_pattern Optional[str] None URL regex pattern to filter discovered links.
concurrency int 1 Number of concurrent page scrapes during a crawl.
driver_type Literal['selenium', 'playwright'] 'selenium' Browser driver backend (selenium or playwright).
browser Literal['chrome', 'firefox', 'edge', 'safari', 'undetected', 'webkit'] 'chrome' Browser to launch.
headless bool True Run browser in headless mode.
parse_videos bool True Extract video links from pages.
parse_navs bool False Extract navigation menus as markdown.
parse_tables bool True Extract tables as markdown.
content_format Literal['markdown', 'text'] 'markdown' How to format extracted content — markdown converts HTML to markdown, text extracts plain text.
content_extraction Literal['auto', 'trafilatura', 'markdown', 'text'] 'auto' Content extraction strategy. auto tries trafilatura first then falls back to markdownify. trafilatura forces trafilatura (raises ImportError if not installed). markdown uses markdownify directly. text extracts plain text.
trafilatura_fallback_threshold float 0.1 Minimum ratio of trafilatura output length to raw text length. If below this threshold in auto mode, falls back to markdownify. Default 0.1.
extract_only Optional[bool] None Controls which documents are emitted. - None (default): auto-detect — True when objective, plan, or selectors is provided (targeted extraction implies the caller wants only the structured results), False otherwise (plain page scrape yields full content). - True: force-yield ONLY content_kind="selector" documents from result.extracted_data. - False: always emit full-page markdown/trafilatura, fragments, tables, videos, navs alongside selector docs.
llm_client Optional[Any] None LLM client for plan auto-generation (required when objective is provided without a plan).
plans_dir Optional[str] None Directory for plan caching.
save_plan bool False Persist auto-generated plans after scraping.
max_refinement_attempts int 1 How many LLM refinement passes to allow when the first plan's extraction scores poorly (empty rows, mostly-null fields, or step errors). Set to 0 to disable. Default 1 — so at most 2 LLM calls total per URL. Only applies when the plan is LLM-generated; explicit/cached plans are never refined.
jsonld_types Optional[List[str]] None Control which JSON-LD @type values are extracted. - None (default): extract all supported types via EXTRACTOR_REGISTRY. - Non-empty list (e.g. ["Product", "Event"]): extract only the listed types. Note that alias types are separate registry keys and must be listed explicitly — e.g. to capture both Product and IndividualProduct nodes, pass ["Product", "IndividualProduct"]. - Empty list []: disable all JSON-LD extraction.
**kwargs Any {} Passed through to AbstractLoader.

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