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.
43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
# Advanced control flow with IF, EXISTS, and REPEAT
|
|
|
|
# Define reusable procedures
|
|
PROC handle_cookie_banner
|
|
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept-cookies`
|
|
IF (EXISTS `.privacy-notice`) THEN CLICK `.dismiss-privacy`
|
|
ENDPROC
|
|
|
|
PROC scroll_to_load
|
|
SCROLL DOWN 500
|
|
WAIT 0.5
|
|
ENDPROC
|
|
|
|
PROC try_login
|
|
CLICK `#email`
|
|
TYPE "user@example.com"
|
|
CLICK `#password`
|
|
TYPE "secure123"
|
|
CLICK `button[type="submit"]`
|
|
WAIT 2
|
|
ENDPROC
|
|
|
|
# Main script
|
|
GO https://example.com
|
|
WAIT 2
|
|
|
|
# Handle popups
|
|
handle_cookie_banner
|
|
|
|
# Conditional navigation based on login state
|
|
IF (EXISTS `.user-menu`) THEN CLICK `.dashboard-link` ELSE try_login
|
|
|
|
# Repeat scrolling based on content count
|
|
REPEAT (scroll_to_load, 5)
|
|
|
|
# Load more content while button exists
|
|
REPEAT (CLICK `.load-more`, `document.querySelector('.load-more') && !document.querySelector('.no-more-content')`)
|
|
|
|
# Process items conditionally
|
|
IF (`document.querySelectorAll('.item').length > 10`) THEN EVAL `console.log('Found ' + document.querySelectorAll('.item').length + ' items')`
|
|
|
|
# Complex condition with viewport check
|
|
IF (`window.innerWidth < 768 && document.querySelector('.mobile-menu')`) THEN CLICK `.mobile-menu-toggle` |