Extraction Script
Every task includes an Extraction Script field in the editor. This JavaScript code runs in the browser context to parse the final page state.Input
The script has access to:document: The DOM of the page.$$data.html(): A helper to get the raw HTML string (including Shadow DOM if enabled).variables: Any runtime variables defined in the task.
Output
The script must return a value (String, Object, Array). This value is saved as theresult of the execution.
- JSON: Automatically formatted.
- CSV: If
extractionFormatis set tocsv, figranium attempts to convert an array of objects to CSV.
Example: Extracting a Product List
Example: Extracting a Single Value
Handling Dynamic Content
If the page loads content dynamically (AJAX), ensure your task includeswait or wait_selector actions before the extraction script runs. The script executes only after the last action completes.
CSV Formatting
If you select CSV as the output format:- Ensure your script returns an Array of Objects.
- Keys in the first object become the CSV headers.
- figranium handles quoting and escaping automatically.