Schedule icon
Webhook icon
Script icon
If icon
SlackIncomingWebhook icon
OutputValues icon

Automated LLM Web Documentation Harvester with Crawl4AI

Crawl web documentation with Crawl4AI in Kestra. Extract token-optimized Markdown, bypass anti-bot shields, and sink clean text to lakehouse storage.

Categories
AIData

Building high-accuracy Retrieval-Augmented Generation (RAG) knowledge bases and AI agents requires fresh, high-quality documentation. However, extracting content from modern web documentation is fraught with operational challenges: single-page applications require client-side JavaScript rendering, anti-bot shields block simple HTTP request scripts, and raw HTML dumps contain thousands of boilerplate tokens (navigation menus, cookie banners, tracking scripts, and footers) that pollute vector search results and inflate LLM inference costs.

This blueprint automates web scraping and documentation harvesting using Crawl4AI, the open-source crawler built specifically for AI and LLMs. It dynamically ingests target URLs, launches an isolated headless Chromium browser with stealth anti-bot protection and session cookie injection, extracts clean token-optimized Markdown, and outputs metrics to Slack and downstream vector chunking DAGs.

How it works

  1. Dynamic URL Ingestion: The flow accepts a dynamic array of target web addresses (target_urls) via manual execution parameters, scheduled cron triggers, or authenticated inbound HTTP webhooks.
  2. Headless Chromium Execution: Launches Playwright with Chromium inside an isolated Docker container (python:3.11-slim). Renders client-side dynamic JavaScript (React, Vue, Docusaurus, Next.js) and waits for full DOM hydration.
  3. Anti-Bot Stealth & Authentication:
    • Randomizes viewport fingerprints and masks navigator.webdriver flags to pass basic bot verifications.
    • Supports injecting authenticated session cookies (AUTH_SESSION_COOKIE) to crawl private intranets, Notion workspaces, or enterprise portals behind logins.
  4. Fit Markdown Extraction: Applies Crawl4AI heuristic filtering to strip out <nav>, <header>, <footer>, <aside>, and cookie overlays, producing clean structured Markdown with headers and code blocks preserved.
  5. Downstream Quality Gate & Alerting: An io.kestra.plugin.core.flow.If evaluates scraped page counts:
    • On Success: Dispatches a Slack scorecard detailing scraped page counts, total words, and estimated LLM token volume.
    • On Warning: Emits an alert if all URLs failed or timed out.
  6. Typed Execution Outputs: Exposes pages_scraped, total_words, and estimated_tokens via OutputValues for downstream vector database embedding flows (Milvus, Qdrant, Pinecone).

What you get

  • LLM-Ready Clean Markdown: Strips up to 80% of unnecessary HTML boilerplate, drastically cutting vector embedding costs and preventing RAG retrieval confusion.
  • Dynamic Cross-Domain Scraping: Supports scraping any public or authenticated documentation portal on demand.
  • Single-Page App (SPA) Support: Full headless browser renders dynamic client-side JavaScript that standard curl/requests libraries cannot see.
  • Observability & Triage: Automatically tracks word counts, token estimates, and crawler latency across every execution.

Expected outputs

Downstream chunking and vector ingestion workflows can reference the typed metrics produced by output_crawl_summary:

Output Variable Description Expression Example
pages_scraped Number of web pages successfully converted to Markdown {{ outputs.output_crawl_summary.values.pages_scraped }}
total_words Total word count extracted across all pages {{ outputs.output_crawl_summary.values.total_words }}
estimated_tokens Estimated token footprint for LLM context windows {{ outputs.output_crawl_summary.values.estimated_tokens }}
storage_destination Cloud storage destination path {{ outputs.output_crawl_summary.values.storage_destination }}
duration_seconds Total end-to-end crawling execution time {{ outputs.output_crawl_summary.values.duration_seconds }}

Who it's for

  • AI Engineers & LLMOps Teams feeding live technical documentation into RAG knowledge retrieval systems.
  • Data Platform Architects automating unstructured web data extraction into cloud data lakes.
  • Product Operations Teams synchronizing external SaaS documentation and developer APIs into internal AI assistants.

Why orchestrate this with Kestra

Running standalone scraping daemons requires maintaining heavy Playwright server fleets, managing memory leaks, and configuring scheduled retries. Kestra provides:

  • Ephemeral Container Isolation: Spawns isolated Chromium browser processes with all required Linux dependencies (--with-deps), auto-terminating upon task completion with zero leaked memory.
  • Declarative Webhooks & Schedules: Easily switch between weekly scheduled refreshes (0 3 * * 0) and event-driven webhook execution triggered by ChatOps or Git commit pushes.
  • Secure Credential Injection: Injects session cookies and cloud storage keys from Kestra's encrypted secret store without exposing credentials in plaintext scripts.

Prerequisites

  • An incoming Slack webhook URL for execution metrics digests.
  • (Optional) An active session cookie for private or authenticated portals.
  • (Optional) Cloud storage credentials (AWS S3, Google Cloud Storage) if writing output directly to cloud buckets.

Secrets

Configure the following secrets in your Kestra namespace or instance settings:

Secret Name Description Example
SLACK_WEBHOOK_URL Destination Slack webhook URL for crawl metrics scorecards https://hooks.slack.com/services/T00/B00/X00
WEBHOOK_KEY Secret authentication key for on-demand webhook execution whk_live_c1d2e3f4g5
AUTH_SESSION_COOKIE (Optional) Session cookie string for scraping private portals session_id=abc123xyz; token=eyJhbGc...
AWS_ACCESS_KEY_ID (Optional) AWS access key ID for S3 bucket uploads AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY (Optional) AWS secret access key for S3 bucket uploads ••••••••••••

Quick start

  1. Import this blueprint into your Kestra instance under the company.ai namespace.
  2. Add your SLACK_WEBHOOK_URL into Settings > Secrets.
  3. Click Execute, inspect the default URLs, and click Run to observe Crawl4AI rendering and Markdown extraction.
  4. To scrape custom documentation, pass your URLs into the target_urls array parameter.
  5. Enable the weekly_docs_refresh_schedule or integrate the webhook URL into your ChatOps bot.

Common pitfalls & notes

  • Docker Shared Memory: Chromium requires adequate shared memory in container runtimes. The blueprint includes --disable-dev-shm-usage and --no-sandbox flags to prevent memory crashes on resource-constrained workers.
  • Rate Limiting: When crawling hundreds of pages from a single domain, add polite pacing delays to prevent aggressive IP rate-limiting by cloud firewalls.
  • Hard CAPTCHAs: Complex interactive puzzle challenges (e.g. image selection) cannot be solved automatically without integrating third-party CAPTCHA solving proxies.

How to extend

  • Vector Database Ingestion: Chain a downstream task to chunk the generated Markdown and upsert vectors into Milvus or Qdrant using flows/clickhouse-to-milvus-cdc-vector-sync.yaml.
  • Sitemap Auto-Discovery: Extend the Python script with crawl4ai sitemap parsers to recursively crawl entire documentation hierarchies from a root URL.
  • Multi-Modal Image Extraction: Enable image URL extraction to download diagrams and flowcharts for vision-capable LLMs like Gemini and GPT-4o.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.