This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
🫎🔬 Chopperfix
Chopperfix is a powerful library designed to automate and optimize web browser interactions. This tool integrates with Selenium and Playwright, leveraging artificial intelligence and language models to analyze, log, and continuously improve the actions performed in web environments, enabling robust automation and self-healing capabilities.
🚀 Key Features
-
🎯 Action Decorators: Automate and log actions with detailed descriptions and context using the
@chopperdocdecorator, providing clear insights into each interaction. -
🗃️ Robust Pattern Storage: A solid system for storing patterns, tracking their usage, and evaluating their effectiveness, allowing continuous improvement of selectors and action execution.
-
🤖 AI Integration: Uses LangChain and language models (e.g., GPT) to dynamically enhance selectors and interactions based on changes in the DOM of the web pages.
-
🌐 Wide Compatibility: Works seamlessly with both Selenium and Playwright, maximizing automation capabilities and ensuring smooth integration with various browsers and web environments.
🔧 API Key and OpenAI Configuration
To use ChopperFix with OpenAI models, you need to configure an API Key:
-
Obtain an OpenAI API Key:
- Visit OpenAI’s website and create an account.
- Generate an API Key from the dashboard.
-
Set the API Key as an Environment Variable:
- In your command line or terminal, set the following environment variable:
export OPENAI_API_KEY='your_openai_api_key_here'
- In your command line or terminal, set the following environment variable:
📚 Installation
To install ChopperFix, use the following command:
pip install chopperfix
Ensure that all dependencies such as LangChain, Selenium, Playwright, SQLAlchemy, and spaCy are properly configured in your environment.
🛠️ Integration with Playwright
-
Setting up Playwright
- Install Playwright:
pip install playwright playwright install
- Install Playwright:
-
Implementation with ChopperFix
- Example of using ChopperFix with Playwright:
from playwright.sync_api import sync_playwright from chopperfix.chopper_decorators import chopperdoc class CustomPlaywright: def __init__(self, timeout=10000, retry_attempts=1): self.playwright = sync_playwright().start() self.browser = self.playwright.chromium.launch(headless=False) self.page = self.browser.new_page() self.page.set_default_timeout(timeout) self.retry_attempts = retry_attempts @chopperdoc def perform_action(self, action, **kwargs): for attempt in range(self.retry_attempts): try: if action == 'click': self.page.click(kwargs['selector']) elif action == 'type': self.page.fill(kwargs['selector'], kwargs.get('text', '')) elif action == 'press': self.page.press(kwargs['selector'], kwargs.get('key', '')) elif action == 'navigate': self.page.goto(kwargs.get('url', '')) break # Exits loop if action is successfully performed except Exception as e: print(f"[ERROR] Attempt {attempt + 1} failed: {e}")
🖥️ Integration with Selenium
-
Setting up Selenium
- Install Selenium:
pip install selenium
- Download the appropriate WebDriver for your browser (e.g., ChromeDriver for Chrome).
- Install Selenium:
-
Implementation with ChopperFix
- Example of using ChopperFix with Selenium:
from selenium import webdriver from chopperfix.chopper_decorators import chopperdoc class CustomSelenium: def __init__(self, driver_path='path/to/chromedriver'): self.driver = webdriver.Chrome(executable_path=driver_path) @chopperdoc def perform_action(self, action, **kwargs): try: element = self.driver.find_element_by_css_selector(kwargs['selector']) if action == 'click': element.click() elif action == 'type': element.clear() element.send_keys(kwargs.get('text', '')) elif action == 'navigate': self.driver.get(kwargs.get('url', '')) except Exception as e: print(f"[ERROR] Action '{action}' execution failed: {e}")
📊 Pattern Storage and Analysis
Each recorded interaction is stored in the database using the Pattern model, tracking statistics such as usage count, success rate, and the weight of each pattern. This allows optimization of future automation actions, improving selector robustness and self-healing performance.
💡 Ideas and Future Enhancements
- ✨ Support for more browsers: We plan to expand compatibility to other browsers for wider coverage.
- 🔧 Continuous improvement of patterns: Ongoing optimization of selectors and action patterns using advanced AI techniques.
- 📈 Advanced analysis and visualization: More tools for analyzing patterns and actions will be added, providing optimization insights driven by data.
📝 Contribution
If you'd like to contribute to ChopperFix:
- Fork the project.
- Create a new branch (
git checkout -b feature/new-feature). - Make your changes and commit them (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature/new-feature). - Open a Pull Request for review.
Suggestions to Enhance Self-Healing
-
Expanding Support for Element Identifiers:
- Dynamic XPath Generation: Implement a dynamic XPath generator that adapts to small changes in the DOM structure, improving the resiliency of element identification.
- Fallback Identifiers: Add backup identifiers for each element (e.g., using
data-*attributes if available) that can be used if the primary selector fails.
-
Improved Context Detection:
- Text-Based Detection: If the selector fails, perform a search based on the visible text of the element to re-identify it.
- Visual Analysis with OpenCV: Utilize visual analysis techniques (e.g., OpenCV) to locate elements on the page even if their position or appearance has changed.
-
Proactive Feedback and Continuous Learning:
- Store and Reevaluate Failures: Create a feedback system that adjusts selector patterns based on each failure, improving future identification.
- Detailed Failure Reports: Generate detailed logs and suggestions on how to resolve issues encountered during automation, such as alternatives to selectors.
-
Selector Heuristics and Machine Learning:
- Heuristic Selector Ranking: Use historical data to rank the robustness of various selector strategies (CSS, XPath, ID, etc.) and prioritize those that have shown higher reliability.
- Learning-based Recovery: Train a model to predict the likelihood of a selector’s success based on past data, automatically switching to alternative strategies when necessary.
Metadata
Release files for ChopperFix 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chopperfix-0.0.1.tar.gz | 11.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ChopperFix-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.0 kB
Release files / chopperfix-0.0.1.tar.gz
| Download URL | chopperfix-0.0.1.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3709cb7d4670f5876efa71b72b1c6bd3c1906aca3547b13bf1042dfe21fef61e
|
|
BLAKE2b-256 checksum How to use checksums |
3763ac98e5dd9d3ee7ed1cc3c8f9ed6600be4fc9f4aa490dc2bd58ab0f630abc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|
Release files / ChopperFix-0.0.1-py3-none-any.whl
| Download URL | ChopperFix-0.0.1-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6febc53f7ae3e97d399e4136d85075ab0d7b4d58b0307e65efbfb618f017b370
|
|
BLAKE2b-256 checksum How to use checksums |
b246417b78e9f75267561fdc138907050957b69bb54ecf6347ead5c7df09a3c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|