Selenium Execution Engine
A flexible, JSON-driven execution engine for Selenium. This engine allows you to define navigation steps, interactions, and data extraction rules using a simple JSON configuration. It can be used as a standalone Command Line Interface (CLI) tool or imported as a Python library.
Installation
- Clone this repository.
- Install the package in editable mode (which also installs all dependencies):
pip install -e .
- Make sure you have the appropriate WebDriver installed (e.g., ChromeDriver for Google Chrome) and available in your system's PATH.
Usage as CLI
Once installed, the CLI tool selenium-engine will be available in your PATH. You can run it directly:
selenium-engine config.json
To save the extracted results to a file, use the -o or --output flag:
selenium-engine config.json -o results.json
To override the number of iterations when using loop mode, use the -i or --iterations flag:
selenium-engine config.json -i 5
Usage as a Library
You can integrate the engine into your Python scripts.
import json
from selenium_engine import execute_scraping
config_json = """
{
"target_url": "https://example.com",
"actions": [
{"type": "wait", "selector": "h1", "timeout": 5}
],
"extraction_schema": {
"items": {
"fields": {
"title": {"selector": "h1", "type": "text"}
}
}
}
}
"""
# You can pass the JSON string directly
results = execute_scraping(config_json)
print(json.dumps(results, indent=2))
# Or you can pass a parsed dictionary
config_dict = json.loads(config_json)
results_dict = execute_scraping(config_dict)
print(json.dumps(results_dict, indent=2))
JSON Configuration Schema
The engine uses a JSON schema to validate your configuration. Here is an overview of the options:
Basic Structure
{
"target_url": "https://surtido.app/productos",
"selenium_config": {
"driver": "chrome",
"headless": true
},
"actions": [
...
],
"extraction_schema": {
...
}
}
Selenium Configuration (selenium_config)
driver: Browser to use (chrome,firefox,edge,safari). Defaults tochrome.headless: Run in headless mode (true/false). Defaults totrue.arguments: Array of string arguments to pass to the driver.page_load_timeout: Timeout in seconds.
Execution Mode (execution_mode)
Allows running the engine in a loop instead of a single linear execution.
type: Eitherlinearorloop.iterations: Number of times to loop (requirestarget_urlat the root).loop_urls: Array of URLs to loop through.
Note: If you use execution_mode, you can omit target_url at the root if you provide loop_urls.
Actions (actions)
An array of steps to execute sequentially on the page.
Wait Action
Waits for an element to be present in the DOM.
{"type": "wait", "selector": ".product-list", "timeout": 10}
Click Action
Clicks on an element.
{"type": "click", "selector": "#submit-btn"}
Scroll Action
Scrolls the page.
{"type": "scroll", "target": "bottom"}
// OR
{"type": "scroll", "amount": 500}
Input Action
Types text into an input field.
{"type": "input", "selector": "#search-box", "value": "laptops"}
Extraction Schema (extraction_schema)
Defines how to extract data from the page after actions are completed.
Extracting a Single Item
"extraction_schema": {
"items": {
"fields": {
"title": {"selector": "h1.title", "type": "text"}
}
}
}
Extracting a List of Items
Specify a container selector to loop through multiple elements.
"extraction_schema": {
"items": {
"container": ".product-card",
"fields": {
"title": {"selector": "h2.title", "type": "text"},
"price": {"selector": ".price-tag", "type": "text", "transform": "float"},
"stock": {"selector": ".stock-status", "type": "attribute", "attr": "data-qty"}
}
}
}
Field Configurations:
selector: CSS selector. Set to"self"(or leave empty"") to select the container element itself.type:text(inner text) orattribute(element attribute).attr: Required if type isattribute. Name of the attribute.transform: Optional. Cast the value tofloat,int,string, orbool.
BeautifulSoup Extraction
Under the hood, once actions are completed, the engine retrieves the page source and uses BeautifulSoup to parse and extract the configured fields. This yields high-performance queries and allows flexible scraping features like referencing the container element itself.
Modularity
To add new actions, simply create a new .py file in the selenium_engine/actions/ directory. It should inherit from BaseAction and implement the execute(self, driver, action_config) method. Then, register it in selenium_engine/actions/__init__.py and update the schema.json to allow the new action type.
Metadata
Release files for selenium-execution-engine 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| selenium_execution_engine-1.0.0.tar.gz | 11.1 kB | Without provenance | Details for selenium_execution_engine-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| selenium_execution_engine-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for selenium_execution_engine-1.0.0-py3-none-any.whl |
Total release size: 23.7 kB
Release files / selenium_execution_engine-1.0.0.tar.gz
| Download URL | selenium_execution_engine-1.0.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d369a264a9d3a5d51259dcc88a98d768f46d850eeff4e672a44b4d5c3f5f74a
|
|
BLAKE2b-256 checksum How to use checksums |
911f07524fc2c0754c88c3da1b05f5e6586ee1ed2e4fb9833980dbf65d842fbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / selenium_execution_engine-1.0.0-py3-none-any.whl
| Download URL | selenium_execution_engine-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad4a5daf438ad2554926ececbcfeb681acb0761e2a33ec0c16dd6e0ea0fca66b
|
|
BLAKE2b-256 checksum How to use checksums |
f485a0a4b5b1dc92860ca32d0ed0a9556a31849d4f10d15f31d704f9fc9eb7b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for selenium-execution-engine 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.