docs/examples/c4a_script/tutorial/README.md
A comprehensive web-based tutorial for learning and experimenting with C4A-Script - Crawl4AI's visual web automation language.
Clone and Navigate
git clone https://github.com/unclecode/crawl4ai.git
cd crawl4ai/docs/examples/c4a_script/tutorial/
Install Dependencies
pip install -r requirements.txt
Launch the Server
python server.py
Open in Browser
http://localhost:8000
š Try Online: Live Demo
# Basic interaction
GO playground/
WAIT `body` 2
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept`
CLICK `#start-tutorial`
GO urlWAIT selector timeout or WAIT secondsCLICK selectorTYPE "text"SCROLL DOWN/UP amountIF (condition) THEN actionREPEAT (action, condition)EVAL codeSET name = "value"The tutorial includes a fully interactive web app with:
Load pre-written examples demonstrating:
Learn basic commands and syntax:
GO https://example.com
WAIT `.content` 5
CLICK `.button`
Master waiting strategies and conditionals:
IF (EXISTS `.popup`) THEN CLICK `.close`
WAIT `.results` 10
Fill and submit forms:
CLICK `#email`
TYPE "[email protected]"
CLICK `button[type="submit"]`
Build complex automation flows:
PROC login
CLICK `#username`
TYPE $username
CLICK `#password`
TYPE $password
CLICK `#login-btn`
ENDPROC
SET username = "demo"
SET password = "pass123"
login
Handle the cookie banner and newsletter popup that appear on page load.
Successfully log into the application using the demo credentials.
Use infinite scroll to load all 100 products in the catalog.
Complete the entire multi-step survey form.
Create a script that logs in, browses products, and exports data.
# Good - specific
CLICK `button.submit-order`
# Bad - too generic
CLICK `button`
# Check for common popups
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept`
IF (EXISTS `.newsletter-modal`) THEN CLICK `.close`
# Wait for elements before interacting
WAIT `.form` 5
CLICK `#submit`
PROC handle_popups
IF (EXISTS `.popup`) THEN CLICK `.close`
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept`
ENDPROC
# Use anywhere
handle_popups
"Element not found"
"Timeout waiting for selector"
"Missing THEN keyword"
IF (condition) THEN actionOnce you've mastered C4A-Script in the tutorial, use it with Crawl4AI:
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
config = CrawlerRunConfig(
url="https://example.com",
c4a_script="""
WAIT `.content` 5
IF (EXISTS `.load-more`) THEN CLICK `.load-more`
WAIT `.new-content` 3
"""
)
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(config=config)
Check the scripts/ folder for complete examples:
01-basic-interaction.c4a - Getting started02-login-flow.c4a - Authentication03-infinite-scroll.c4a - Dynamic content04-multi-step-form.c4a - Complex forms05-complex-workflow.c4a - Full automationtutorial/
āāā server.py # Flask application server
āāā assets/ # Tutorial-specific assets
ā āāā app.js # Main application logic
ā āāā c4a-blocks.js # Custom Blockly blocks
ā āāā c4a-generator.js # Code generation
ā āāā blockly-manager.js # Blockly integration
ā āāā styles.css # Main styling
āāā playground/ # Interactive demo environment
ā āāā index.html # Demo web application
ā āāā app.js # Demo app logic
ā āāā styles.css # Demo styling
āāā scripts/ # Example C4A scripts
āāā index.html # Main tutorial interface
assets/app.js)Main application controller managing:
assets/blockly-manager.js)Visual programming interface:
Powers the recording functionality:
assets/c4a-blocks.js)assets/c4a-generator.js)assets/blockly-manager.js)assets/styles.css# server.py configuration
PORT = 8000
DEBUG = True
THREADED = True
GET / - Main tutorial interfaceGET /playground/ - Interactive demo environmentPOST /execute - Script execution endpointGET /examples/<script> - Load example scriptsPort Already in Use
# Kill existing process
lsof -ti:8000 | xargs kill -9
# Or use different port
python server.py --port 8001
Blockly Not Loading
Recording Issues
Enable detailed logging by setting DEBUG = True in assets/app.js
git checkout -b feature/my-featureHappy Automating! š
Need help? Check our documentation or open an issue on GitHub.