Here's a Python script to open lmarena.ai using Selenium with Chrome. The script handles automatic ChromeDriver management and includes proper waiting/cleanup:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
# Initialize Chrome options
options = webdriver.ChromeOptions()
options.add_argument("start-maximized") # Open browser maximized
# Initialize WebDriver with automatic ChromeDriver management
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()),
options=options
)
try:
# Open lmarena.ai
driver.get("https://lmarena.ai")
# Wait for page to load (checks for <body> tag existence)
WebDriverWait(driver, timeout=10).until(
lambda d: d.find_element("tag name", "body")
)
print("Page loaded successfully!")
# Keep browser open for 10 seconds (or replace with input prompt)
driver.implicitly_wait(10)
except Exception as e:
print(f"An error occurred: {str(e)}")
finally:
# Clean up - close the browser
driver.quit()
Key features:
- Automatic ChromeDriver management using
webdriver-manager
- Browser opens maximized
- Proper waiting for page load completion
- Error handling
- Resource cleanup with
driver.quit() in finally block
Prerequisites:
- Install required packages:
pip install selenium webdriver-manager
- Ensure Google Chrome is installed on your system
To modify:
Note: The website might have bot protection mechanisms. If you encounter access issues, you may need to:
- Add user-agent rotation
- Implement more sophisticated waiting strategies
- Handle CAPTCHAs (which typically require manual intervention)
Would you like me to add any of these advanced features to the script?