A robust, stealthy, and self-correcting web automation agent built with Playwright and Google Gemini AI. This project mimics human behavior to bypass anti-bot protections on sites like BookMyShow and uses AI to understand user intent (e.g., mapping "book home" to the "Book Tickets" button).
- Bypasses Bot Detection: Uses
playwright-stealthto mask automation signals (navigator.webdriver, headers). - Human-Like Interaction:
- Typing: Simulates variable typing speeds, typos (5% chance), and backspace corrections.
- Mouse: Random mouse jitters and reaction delays.
- Fail-Safe Navigation: If a click is blocked (e.g., hidden element), it intelligently extracts the link and navigates directly.
- Instead of fragile selectors (
#btn-123), the agent looks at the page and understands meaning. - Example: Command
"I want to buy seats"-> Agent finds and clicks the "Book Tickets" button.
- Works even without an AI key!
- Uses
rapidfuzzto find elements based on string similarity (e.g., "book tckets" finds "Book Tickets").
| File | Description |
|---|---|
scripts/bookmyshow_stealth.py |
The Main Engine. Integrates stealth, automation, and decision-making logic. |
scripts/ai_matcher.py |
The Brain. Uses Gemini API to analyze page elements and find the best match for a user's intent. |
scripts/fuzzy_matcher.py |
The Backup. Finds elements using fuzzy string matching when AI is unavailable. |
scripts/element_extractor.py |
The Eyes. Scrapes interactive elements (buttons, links) from any page. |
utils/helpers.py |
The Toolbox. Shared functions for element extraction and selector logic. |
-
Clone the repository:
git clone <repo-url> cd playwright-automation
-
Set up Virtual Environment:
python -m venv venv .\venv\Scripts\activate # Windows source venv/bin/activate # Mac/Linux
-
Install Dependencies:
pip install -r requirements.txt playwright install chromium
-
Set up Environment Variables (Optional, for AI features): Create a
.envfile:GOOGLE_API_KEY=your_gemini_api_key_here
Navigate to a movie flow with human-like behavior.
# Basic Usage
python scripts/bookmyshow_stealth.py --movie "Border 2" --city "Mumbai"Tell the script what to do in plain English.
With AI (Requires API Key):
python scripts/bookmyshow_stealth.py --movie "Border 2" --city "Mumbai" --find "book home"
# Result: AI understands "book home" contextually means "Book Tickets" and clicks it.With Fuzzy Match (No API Key):
python scripts/bookmyshow_stealth.py --movie "Border 2" --city "Mumbai" --find "book ticets"
# Result: Finds "Book Tickets" based on spelling similarity.- Python 3.8+
playwrightplaywright-stealthgoogle-generativeairapidfuzzrich(for beautiful console output)