Train once, automate forever. Grivredr uses Claude AI to learn how to navigate government portals, then generates production-ready Python scrapers that work without ongoing AI costs.
π― Learn any portal in 2-3 minutes β’ π° ~$0.12 one-time cost β’ π Unlimited free usage after
# 1. Clone and setup
git clone https://github.com/yourusername/grivredr.git
cd grivredr
./quickstart.sh
# 2. Train your first portal
python cli/train_cli.py abua_sathi --district ranchi
# 3. Test it
python tests/test_abua_sathi_live.pyπ New here? Check out GETTING_STARTED.md for a complete walkthrough.
- Claude Vision analyzes form structure from screenshots
- Interactive exploration automatically clicks dropdowns and detects cascading fields
- Hybrid strategy: Fast Playwright + intelligent Browser Use AI fallback
- JavaScript monitoring captures AJAX calls and dynamic behavior
- Self-healing: Validates and fixes generated code automatically (3 attempts)
- Pattern library: Learns from successful scrapers to improve future ones
- Smart templates: Handles Select2, cascading dropdowns, AJAX submissions
- Zero AI costs after training - scrapers run standalone
- Network tab analysis: Detects APIs and generates direct HTTP calls (5-10x faster than browser)
- Confidence scoring: Only proceeds when form understanding is >70%
- Human fallback: Record your actions if AI fails (becomes ground truth)
- Cost optimization: AI response caching, model selection per task
| Phase | Cost | Frequency |
|---|---|---|
| Training | ~$0.12 per portal | One-time only |
| Execution | $0.00 | Unlimited forever |
Example: Train 10 portals ($1.20) β Submit unlimited requests ($0.00)
Grivredr uses a 4-phase AI agent pipeline:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Phase 1: Form Discovery (30-60s) β
β β’ Claude Vision analyzes screenshots β
β β’ Interactive exploration (dropdowns, cascading fields) β
β β’ Hybrid: Playwright first, Browser Use AI if needed β
β β’ Confidence score: >0.6 to proceed β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Phase 2: JavaScript Analysis (10-20s) β
β β’ Monitors JS runtime during form interaction β
β β’ Detects AJAX calls, dynamic behavior, event handlers β
β β’ Identifies API endpoints for direct HTTP calls β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Phase 3: Test Validation (30-60s) β
β β’ Tests empty submission (finds required fields) β
β β’ Tests field types, cascading dropdowns β
β β’ Full submission with mock data β
β β’ Confidence score: >0.7 to proceed β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Phase 4: Code Generation (20-40s) β
β β’ Claude Opus generates Python scraper β
β β’ Self-healing validation loop (3 attempts) β
β β’ Stores pattern in knowledge base β
β β’ Saves to outputs/generated_scrapers/ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Total: ~2-3 minutes, ~$0.12 per portal
./quickstart.shHandles everything: dependencies, Playwright, and configuration.
1. Install Python Dependencies
pip install -r requirements.txt2. Install Playwright Browsers
python -m playwright install chromium3. Configure API Key
cp .env.example .env
# Edit .env and add your MegaLLM API keyGet your API key: https://app.mega-llm.com
# Basic training
python cli/train_cli.py <portal_name> --district <district>
# Example: Train Jharkhand's Abua Sathi portal
python cli/train_cli.py abua_sathi --district ranchi
# With custom URL
python cli/train_cli.py new_portal --district mumbai \
--url https://portal.example.com/complaintTraining Options:
--headless # Run browser in headless mode
--no-hybrid # Disable hybrid discovery (Playwright only)
--browser-use-first # Try Browser Use AI first
--no-recording # Disable human recording fallbackfrom outputs.generated_scrapers.ranchi_district.portals.abua_sathi import AbuaSathiScraper
async def submit_complaint():
scraper = AbuaSathiScraper(headless=True)
result = await scraper.submit_grievance({
'name': 'John Doe',
'contact': '9876543210',
'village_name': 'Test Village',
'description': 'Street light not working'
})
print(f"Success: {result['success']}")
if result.get('tracking_id'):
print(f"Tracking ID: {result['tracking_id']}")# Test live scraper (visible browser)
python tests/test_abua_sathi_live.py
# Run all tests
pytest tests/- β Hybrid Discovery Strategy - Intelligently combines Playwright + Browser Use AI
- β Claude Vision - Analyzes form structure from screenshots
- β Interactive Exploration - Automatically clicks dropdowns and detects fields
- β Network Monitoring - Captures API calls and generates direct HTTP code
- β Event Listener Detection - Inspects blur/focus/input handlers
- β Self-Healing - Validates and fixes code automatically
- β Pattern Library - Learns from successful scrapers
- β API-Aware - Generates direct HTTP calls when possible (5-10x faster)
- β Framework Detection - Handles Select2, Chosen.js, cascading dropdowns
- β Native Anthropic SDK - Official Python SDK with MegaLLM
- β LangChain Integration - Optional for advanced workflows
- β AI Response Caching - Reduces costs on retries
- β Multi-Agent System - Specialized agents for each phase
- β Simple HTML forms (POST)
- β AJAX-based submissions
- β Select2/Chosen.js dropdowns
- β Cascading dropdowns (parent β child)
- β Multi-step forms
- β File uploads
- β ASP.NET ViewState/EventValidation
Grivredr has successfully trained on:
- Abua Sathi - State grievance system with Select2 dropdowns
- Ranchi Smart - City smart portal with category selection
- Ranchi Municipal - Municipal complaint forms
- π― 95%+ accuracy on form field detection
- β‘ 2-3 minutes average training time
- π° $0.08-0.15 average cost per portal
- β 100% success rate on generated scrapers
python scripts/check_discovery_results.pyShows:
- All form fields discovered
- Dropdown detection (Select2, cascading)
- Required field validation
cat data/training_sessions/portal_name_timestamp.jsonContains:
- Form discovery results
- Test validation results
- Generated code
- Cost breakdown
- Confidence scores
Low confidence score during discovery
- Try hybrid discovery (enabled by default)
- Use
--browser-use-firstfor complex forms
Generated scraper fails validation
- Check session JSON for error details
- Review screenshots in
outputs/screenshots/ - Human recording fallback will be offered
Cascading dropdown timeouts
- Increase wait time in generated code
- Check AJAX patterns in JS analysis results
- Getting Started - Complete beginner's guide
- Project Structure - Codebase organization
- Architecture - System design details
- Claude Code Guide - For Claude Code assistant
- Contributing - Contribution guidelines
- Status - Current features and roadmap
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Areas we'd love help with:
- π Testing on more government portals
- π§ Improving pattern detection
- π Documentation and examples
- π§ͺ Adding test coverage
- π Performance optimizations
- AI: Anthropic Claude (Haiku, Sonnet, Opus) via MegaLLM
- Browser Automation: Playwright + Browser Use
- Language: Python 3.11+
- Knowledge Base: SQLite + Optional ChromaDB
- Testing: Pytest
- Optional: LangChain for advanced workflows
- CAPTCHA: Detected but requires human intervention
- OTP: Requires real phone numbers (not automated)
- Very slow AJAX (>10s): May timeout
- reCAPTCHA: Detected but not bypassed
MIT License - see LICENSE file for details.
- Anthropic - For Claude AI models
- MegaLLM - For affordable Claude API access
- Playwright - For reliable browser automation
- Browser Use - For AI-powered web interaction
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: See docs/ directory
This tool is designed for legitimate civic engagement and automation. Users are responsible for:
- Complying with website Terms of Service
- Respecting rate limits and robot policies
- Using scrapers ethically and legally
No warranty provided. Use at your own risk.
Built with β€οΈ using Claude AI, Playwright, and Python
Star β this repo if Grivredr helps you automate government portals!