This commit introduces a comprehensive set of new scripts and examples to enhance the scripting capabilities of the crawl4ai project. The changes include the addition of several Python scripts for compiling and executing scripts, as well as a variety of example scripts demonstrating different functionalities such as login flows, data extraction, and multi-step workflows. Additionally, detailed documentation has been created to guide users on how to utilize these new features effectively. The following significant modifications were made: - Added core scripting files: , , and . - Created a new documentation file to provide an overview of the new features. - Introduced multiple example scripts in the directory to showcase various use cases. - Updated and to integrate the new functionalities. - Added font assets for improved documentation presentation. These changes significantly expand the functionality of the crawl4ai project, allowing users to create more complex and varied scripts with ease.
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 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() |