Skip to content
renatoxmPublic

About

Crawl4AI implementation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Crawl4AI

Archive websites locally with Crawl4AI (LLM-friendly crawler). Each crawl lands under sites/<hostname>/ as markdown, HTML, and JSON.

Upstream docs: docs.crawl4ai.com · Package: crawl4ai on PyPI (this project uses 0.9.2).

Layout

├── sample_crawl.py        # tracked sample: deep crawl → sites/<host>/
├── crawl_*                # gitignored site-specific scripts (e.g. crawl_repairsnap_*.py)
├── sites/                 # gitignored — downloaded archives
│   └── example.com/       # one folder per hostname
│       ├── index.md
│       ├── index.html
│       ├── index.json
│       └── _manifest.json
├── .venv/                 # gitignored
├── .gitignore
└── README.md

Crawl a site:

python sample_crawl.py https://example.com
# → sites/example.com/

Requirements

  • Python 3.10+
  • Network access (package + Playwright browsers)
  • Optional: sudo for playwright install --with-deps

Install Crawl4AI

1. Create and activate a virtualenv

cd /path/to/this/repo

# with uv (recommended if available)
uv venv .venv
source .venv/bin/activate

# or with stdlib venv
python3 -m venv .venv
source .venv/bin/activate

2. Install the package

# with uv (works when system pip is PEP 668 managed)
uv pip install -U crawl4ai --python .venv/bin/python

# or with pip inside the venv
python -m pip install -U crawl4ai

Pre-release:

pip install crawl4ai --pre

3. Post-install browser setup

crawl4ai-setup
crawl4ai-doctor

If Playwright browsers are missing or crawl4ai-setup fails on sudo deps:

python -m playwright install chromium
# optional (needs sudo):
python -m playwright install --with-deps chromium

# undetected-mode browsers (used by some Crawl4AI features)
python -m patchright install chromium

Health check should crawl https://crawl4ai.com and report success.

Quick usage (Crawl4AI itself)

Python (single page)

import asyncio
from crawl4ai import AsyncWebCrawler

async def main():
    async with AsyncWebCrawler() as crawler:
        result = await crawler.arun(url="https://www.example.com")
        print(result.markdown)

if __name__ == "__main__":
    asyncio.run(main())

Python (deep crawl, no LLM)

import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig, CacheMode
from crawl4ai.content_scraping_strategy import LXMLWebScrapingStrategy
from crawl4ai.deep_crawling import BFSDeepCrawlStrategy
from crawl4ai.markdown_generation_strategy import DefaultMarkdownGenerator

async def main():
    config = CrawlerRunConfig(
        deep_crawl_strategy=BFSDeepCrawlStrategy(
            max_depth=5,
            include_external=False,
            max_pages=400,
        ),
        scraping_strategy=LXMLWebScrapingStrategy(),
        markdown_generator=DefaultMarkdownGenerator(),
        cache_mode=CacheMode.BYPASS,
        stream=True,
        verbose=True,
    )
    async with AsyncWebCrawler() as crawler:
        async for result in await crawler.arun("https://example.com", config=config):
            if result.success:
                print(result.url, len(result.markdown.raw_markdown or ""))

asyncio.run(main())

CLI (crwl)

source .venv/bin/activate

# Basic crawl → markdown
crwl https://www.nbcnews.com/business -o markdown

# Deep crawl (BFS), max pages
crwl https://docs.crawl4ai.com --deep-crawl bfs --max-pages 10

# LLM extraction (needs provider/API key; not used by project scripts)
crwl https://www.example.com/products -q "Extract all product prices"

Other Crawl4AI commands

Command Purpose
crawl4ai-setup Install/configure Playwright browsers and local DB
crawl4ai-doctor Verify install with a live crawl
crwl <url> ... CLI crawler
python -m playwright install chromium Install Chromium for Playwright
python -m patchright install chromium Install Chromium for Patchright

Project scripts

Activate the venv first:

source .venv/bin/activate

Sample deep crawl — sample_crawl.py

Generic starter script (no site-specific logic). Deep-crawls a start URL (BFS, LXML + default markdown, no LLM) into sites/<hostname>/.

python sample_crawl.py https://example.com
python sample_crawl.py https://docs.crawl4ai.com --max-pages 50 --max-depth 2
python sample_crawl.py https://example.com --site my-archive
Flag Meaning
url Start URL (default https://example.com/)
--site NAME Folder name under sites/ (default: hostname)
--max-pages N Cap pages (default 100)
--max-depth N BFS depth (default 3)

Writes path-mirrored .md / .html / .json plus sites/<host>/_manifest.json.

Copy or adapt it for a specific site (e.g. crawl_mysite.py). Files named crawl_* in the project root are gitignored so site-specific scripts stay local.

Output per page

Inside each sites/<host>/ folder:

  • .md — markdown (result.markdown.raw_markdown)
  • .html — raw HTML
  • .json — metadata (url, status, title, links, media, file paths)
  • _manifest.json — crawl summary

sites/ is gitignored so archives stay local and do not bloat the repo.

Git ignore

See .gitignore. Notable entries:

Path Why
sites/ Downloaded site archives
site/ Legacy output folder name
/crawl_* Site-specific crawl scripts in the project root
.venv/ Local virtualenv
__pycache__/ Python bytecode
.env Secrets
.crawl4ai/, Playwright caches Local crawler/browser data if created in-repo

Docker (optional, upstream)

docker pull unclecode/crawl4ai:latest
docker run -d -p 11235:11235 --name crawl4ai --shm-size=1g unclecode/crawl4ai:latest

Dashboard: http://localhost:11235/dashboard · Playground: http://localhost:11235/playground

Notes

  • Prefer the project .venv; do not install into the system Python on PEP 668 distros without a venv.
  • Playwright browser binaries may live under a sandbox cache path; if launch fails with “Executable doesn't exist”, re-run python -m playwright install chromium.
  • Attribution: this project uses Crawl4AI (https://github.com/unclecode/crawl4ai) for web data extraction. Licensed Apache-2.0 upstream.

About

Crawl4AI implementation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages