#!/usr/bin/env python3 """ Browser Automation Tool - Flask Interface (No Gradio Dependencies) """ from flask import Flask, render_template_string, request, jsonify import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import io from PIL import Image import base64 app = Flask(__name__) def setup_driver(headless=True, window_size="1920,1080"): """Setup Chrome driver with options""" chrome_options = Options() if headless: chrome_options.add_argument("--headless") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument(f"--window-size={window_size}") chrome_options.add_argument("--disable-gpu") driver = webdriver.Chrome(options=chrome_options) return driver def navigate_and_screenshot(url, headless=True, window_size="1920,1080"): """Navigate to URL and return screenshot as base64""" try: driver = setup_driver(headless, window_size) driver.get(url) time.sleep(3) # Take screenshot and convert to base64 screenshot = driver.get_screenshot_as_png() driver.quit() # Convert to base64 for web display import base64 screenshot_b64 = base64.b64encode(screenshot).decode('utf-8') return { "success": True, "screenshot": screenshot_b64, "message": "Screenshot captured successfully" } except Exception as e: return { "success": False, "error": str(e), "message": "Error capturing screenshot" } def extract_text_content(url, headless=True): """Extract text content from URL""" try: driver = setup_driver(headless) driver.get(url) time.sleep(2) title = driver.title html = driver.page_source # Simple text extraction from bs4 import BeautifulSoup soup = BeautifulSoup(html, 'html.parser') text = soup.get_text()[:1000] + "..." if len(soup.get_text()) > 1000 else soup.get_text() driver.quit() return { "success": True, "title": title, "content": text, "message": "Content extracted successfully" } except Exception as e: return { "success": False, "error": str(e), "message": "Error extracting content" } # HTML Template HTML_TEMPLATE = ''' Browser Automation Tool - Flask

🌐 Browser Automation Tool - Flask

Simple web interface for browser automation (No Gradio dependencies!)

🌐 Single URL Processing

⚡ Batch Processing

Feature coming soon...

✨ Features

''' @app.route('/') def home(): return render_template_string(HTML_TEMPLATE) @app.route('/screenshot', methods=['POST']) def screenshot(): data = request.json url = data.get('url', '') headless = data.get('headless', True) result = navigate_and_screenshot(url, headless) return jsonify(result) @app.route('/extract', methods=['POST']) def extract(): data = request.json url = data.get('url', '') headless = data.get('headless', True) result = extract_text_content(url, headless) return jsonify(result) if __name__ == "__main__": app.run(host="0.0.0.0", port=7860, debug=False)