- Add playwright-stealth integration with enable_stealth parameter in BrowserConfig - Merge undetected browser strategy into main async_crawler_strategy.py using adapter pattern - Add browser adapters (BrowserAdapter, PlaywrightAdapter, UndetectedAdapter) for flexible browser switching - Update install.py to install both playwright and patchright browsers automatically - Add comprehensive documentation for anti-bot features (stealth mode + undetected browser) - Create examples demonstrating stealth mode usage and comparison tests - Update pyproject.toml and requirements.txt with patchright>=1.49.0 and other dependencies - Remove duplicate/unused dependencies (alphashape, cssselect, pyperclip, shapely, selenium) - Add dependency checker tool in tests/check_dependencies.py Breaking changes: None - all existing functionality preserved 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
"""
|
|
C4A-Script Hello World
|
|
A concise example showing how to use the C4A-Script compiler
|
|
"""
|
|
|
|
from crawl4ai.script.c4a_compile import compile
|
|
|
|
# Define your C4A-Script
|
|
script = """
|
|
GO https://example.com
|
|
WAIT `#content` 5
|
|
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept`
|
|
CLICK `button.submit`
|
|
"""
|
|
|
|
# Compile the script
|
|
result = compile(script)
|
|
|
|
# Check if compilation was successful
|
|
if result.success:
|
|
# Success! Use the generated JavaScript
|
|
print("✅ Compilation successful!")
|
|
print(f"Generated {len(result.js_code)} JavaScript statements:\n")
|
|
|
|
for i, js in enumerate(result.js_code, 1):
|
|
print(f"{i}. {js}\n")
|
|
|
|
# In real usage, you'd pass result.js_code to Crawl4AI:
|
|
# config = CrawlerRunConfig(js_code=result.js_code)
|
|
|
|
else:
|
|
# Error! Handle the compilation error
|
|
print("❌ Compilation failed!")
|
|
|
|
# Get the first error (there might be multiple)
|
|
error = result.first_error
|
|
|
|
# Show error details
|
|
print(f"Error at line {error.line}, column {error.column}")
|
|
print(f"Message: {error.message}")
|
|
|
|
# Show the problematic code
|
|
print(f"\nCode: {error.source_line}")
|
|
print(" " * (6 + error.column) + "^")
|
|
|
|
# Show suggestions if available
|
|
if error.suggestions:
|
|
print("\n💡 How to fix:")
|
|
for suggestion in error.suggestions:
|
|
print(f" {suggestion.message}")
|
|
|
|
# For debugging or logging, you can also get JSON
|
|
# error_json = result.to_json() |