Browser Use A.I. Agent Tutorial: Automatic Basketball Court Booking System in 10 Minutes

Key Takeaways:

💡 Browser Use AI agents can automate basketball court bookings in Hong Kong, eliminating manual booking hassles and competition with scalpers.

💡 Unlike traditional automation tools, Browser Use adapts instantly to website changes and handles complex tasks like CAPTCHAs through AI-powered natural interactions.

💡 Implementation takes just 10 minutes and requires minimal coding knowledge, making automated court booking accessible to users of all technical skill levels.

I posted the use case on my linkedin and people loved it!

Securing a basketball court in Hong Kong has become a digital battleground. Manual booking is tedious, and scalpers dominate the system. But there’s a game-changing solution: Browser Use AI agents.

This tutorial shows you how to build an automated booking system in just 10 minutes. You’ll learn to create an AI agent that handles the entire process – from searching available courts to completing reservations.

Browser Use transforms complex web interactions into simple commands. Unlike traditional automation tools that break when websites change, this AI-powered solution adapts instantly. It understands context, handles CAPTCHAs, and navigates dynamic content effortlessly.

The system we’ll build today works with Hong Kong’s Leisure and Cultural Services Department (LCSD) booking platform.

No more rushing to book at midnight. No more competing with scalpers. Just reliable, automated court bookings when you need them.

Ready to revolutionize your basketball court booking experience? Let’s dive into the setup process.

The pain of booking courts

In Hong Kong, securing a basketball court booking is a daily struggle for sports enthusiasts. The government’s Leisure Link system opens bookings at 7 AM, but slots vanish within seconds. Scalpers exploit this system, snatching courts and reselling them at 300% markups on platforms like Carousell.

Understanding Browser Use

Browser Use transforms complex web automation into simple conversations. It’s an AI-powered tool that lets agents interact with websites naturally, just like humans do. Think of it as your personal web assistant that can click, type, and navigate through any website.

Unlike traditional automation tools that break when websites change, Browser Use adapts instantly. It understands website contexts and can handle dynamic content changes seamlessly. The tool processes visual elements, forms, and navigation patterns in real-time.

Key features make Browser Use stand out. It requires zero maintenance scripts. The AI understands natural language commands. And it handles CAPTCHAs automatically. Most importantly, it works across any website without special configuration.

How to use Browser use

  1. Start by downloading Visual Studio Code from the official Microsoft website.
  2. Then you need to run some commands in your terminal to install browser use, openAI and python.
pip install browser-use
pip install openai
pip install python-dotenv

Browser Use requires Chrome or Firefox. Download your preferred browser if you haven’t already. The system automatically detects and uses your default browser.

3. Create a new project folder and set up a virtual environment inside terminal OR just create a new folder on you desktop.

mkdir court-booking
cd court-booking
python -m venv venv
source venv/bin/activate  # On Windows: venvScriptsactivate

4. You need to edit your .env file by inputting your OpenAPI key. If you are from Hong Kong, you need a VPN to get an OpenAPI key.

OPENAI_API_KEY=your_api_key_here

5. Download this script and name it agent.py OR just click on the box below to download the files directly.

from langchain_openai import ChatOpenAI
from browser_use import Agent
import asyncio

async def main():
    agent = Agent(
        task="""Go to https://www.smartplay.lcsd.gov.hk/
                Login with username: 123456 and password: 123456
                Search for basketball facilities in Central & Western, Eastern, Southern, and Wan Chai
                Look for available slots on Tuesdays, Thursdays, and Saturdays between 7-9am
                Return the available options""",
        llm=ChatOpenAI(model="gpt-4o")
    )
    
    try:
        result = await agent.run()
        print(result)
    except Exception as e:
        print(f"Error occurred: {str(e)}")

if __name__ == "__main__":
    asyncio.run(main())

6. Press RUN inside Visual Studio.

Customization Options

Browser Use offers powerful customization features to tailor your basketball court booking agent. You can modify the search radius to include courts within 5-20 kilometers of your location. Time slot preferences adjust from hourly blocks to full-day bookings.

Location flexibility lets you target multiple districts simultaneously. Add up to 15 different court locations to maximize booking chances. The script accepts both district names and specific venue IDs for precise targeting.

Search criteria enhancements include:

  • Court surface type (indoor/outdoor)
  • Facility amenities (showers, lockers)
  • Price range filters
  • Court size preferences

Fine-tune the booking frequency with custom intervals. Set the agent to check availability every 30 seconds during peak hours and every 5 minutes during off-peak times. This optimizes both success rates and system resources.

Priority settings help when multiple courts match your criteria. Rank venues by distance, price, or custom scoring. The agent automatically selects the best option based on your weighted preferences.

Advanced users can implement conditional booking logic. Create rules like “book outdoor courts only in good weather” or “prefer indoor courts after 6 PM.” The agent adapts its behavior based on real-time conditions.

Best Practices and Tips

Always encrypt your API keys and sensitive data. Store these credentials in environment variables or a secure configuration file. Never commit them directly to your code repository.

Rate limiting is crucial. Add delays between requests to prevent server overload and potential IP blocks. A minimum delay of 2-3 seconds between actions mimics human behavior effectively.

Implement robust error handling with specific exception types. Catch network timeouts, authentication failures, and element location errors separately. This makes debugging easier and improves script reliability.

Log all important operations. Use structured logging to track successful bookings, failed attempts, and system errors. This data helps identify patterns and optimize your booking strategy.

Keep your script modular. Separate the booking logic, authentication, and utility functions into different modules. This makes maintenance and updates simpler.

Test your script during off-peak hours first. This reduces impact on the booking system and helps identify potential issues without affecting other users.

Update your selectors regularly. Website layouts change often, so maintain a configuration file for all CSS selectors and XPaths. This makes updates quick and centralized.

Monitor your script’s memory usage. Clear browser cache periodically and close unused tabs. This prevents resource leaks during long-running sessions.

Set up alerts for critical failures. Configure email or messaging notifications when the script encounters blocking errors. Quick response times minimize booking disruptions.

Conclusion

Browser Use transforms basketball court booking from a tedious task into an automated solution. This AI-powered system saves hours of manual effort while ensuring fair access to public sports facilities. The implementation we’ve explored demonstrates how modern automation tools can tackle real-world challenges effectively.

Beyond court bookings, this framework opens doors to numerous applications. From event ticketing to appointment scheduling, the possibilities are vast. The system’s adaptability makes it valuable for both individual users and organizations seeking efficient booking solutions.

Future enhancements could include multi-location support, advanced scheduling patterns, and integration with calendar apps. The modular design allows for easy updates and feature additions as needs evolve.

Join our growing community of developers and automation enthusiasts. Share your implementations, suggest improvements, and help shape the future of browser automation. Together, we’re making digital tasks simpler and more accessible for everyone.

Remember, responsible automation respects website terms of service and maintains fair access for all users. Let’s build solutions that benefit the entire community.

Related Technologies

  • OpenAI API Documentation: Detailed guides for AI integration
  • Python Asyncio Guide: Learn concurrent programming basics
  • Selenium vs Browser Use Comparison: Understanding key differences

Community Support

  • Stack Overflow Browser Use Tag: Solutions to common challenges
  • Browser Use Weekly Newsletter: Latest updates and tips
  • GitHub Discussions: Technical deep-dives and feature requests

Troubleshooting Tools

  • Browser Use Debug Console: Built-in debugging capabilities
  • Chrome DevTools Guide: Web inspection techniques
  • Error Resolution Database: Common issues and fixes

Stay connected with these resources to keep your automation skills sharp and your agents running smoothly.

Leave a Reply

Your email address will not be published. Required fields are marked *