Skip to main content

AI-powered browser automation with natural language

Project description

BrowserHand

BrowserHand is an AI-powered Python library that allows you to control web browsers using natural language. Built on top of Playwright, it provides a simple and intuitive API to automate web interactions without having to write complex automation code.

Features

  • 🧠 Natural Language Control: Control browsers using plain English instructions
  • 🔍 Smart Data Extraction: Extract structured data from web pages with simple prompts
  • 🔎 DOM Observation: Intelligently identify interactive elements on a page
  • Fast & Reliable: Built on Playwright for cross-browser support and reliability
  • 🔗 Works with existing Playwright code: Integrate with your existing Playwright automation

Installation

pip install browserhand

BrowserHand requires Python 3.7+.

After installing, you'll need to install the Playwright browsers:

playwright install

Quick Start

from browserhand import BrowserHand
from langchain_openai import ChatOpenAI

# Initialize a chat model
llm = ChatOpenAI(model="gpt-4o", temperature=0, api_key="your-openai-api-key")

# Initialize BrowserHand with the model
browser = BrowserHand(llm=llm)

try:
    # Navigate to a website
    browser.goto("https://www.example.com")
    
    # Use natural language to perform actions
    browser.Act("Click on the 'Learn more' button and then scroll down")
    
    # Extract data using natural language
    data = browser.Extract(
        "Find the main heading and the first paragraph of text", 
        {"heading": "string", "paragraph": "string"}
    )
    print(data)
    
    # Get interactive elements
    elements = browser.Observe()
    print(f"Found {len(elements)} interactive elements")
    
finally:
    browser.close()

API Reference

BrowserHand Class

The main class for browser automation with natural language.

browser = BrowserHand(
    llm=None,              # Any LangChain chat model (required)
    headless=False          # Run browser in headless mode
)

Core Methods

  • goto(url: str) -> None: Navigate to the specified URL.
  • Act(prompt: str) -> Dict[str, Any]: Perform actions described in natural language.
  • Extract(instruction: str, schema: Dict[str, str]) -> Dict[str, Any]: Extract data from the page.
  • Observe() -> List[Dict[str, Any]]: Get interactive elements on the page.
  • close() -> None: Close the browser and clean up resources.

Supported LLM Providers

BrowserHand supports any chat model from the LangChain ecosystem, including:

  • OpenAI (via langchain_openai)
  • Azure OpenAI (via langchain_openai)
  • Anthropic (via langchain_anthropic)

Command Line Interface

BrowserHand includes a command line interface:

# Navigate and perform an action
browserhand --url "https://www.example.com" --action "Click on the first button"

# Extract data
browserhand --url "https://www.example.com" --extract "Get the main heading" --schema "heading:string"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

browserhand-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

browserhand-0.1.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file browserhand-0.1.0.tar.gz.

File metadata

  • Download URL: browserhand-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for browserhand-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ed229874ddb98ba34f4fa6b8b202bb99f9a145913e2b4c18934bb47ec5acf28
MD5 78e028f57cbaa86b4ec109585845dadc
BLAKE2b-256 4bbbb9d16690f34139878f139daa9da87b2cf0fd9a41824dc0bb24f7124c39ee

See more details on using hashes here.

File details

Details for the file browserhand-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: browserhand-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for browserhand-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2ed1fcb9ff16a82e859520ce2b8030e6e28e1da5b95f8eda48a100bb8cc3beb
MD5 9dd41323a2ac015a7e7495e8b46e02cd
BLAKE2b-256 28f2229015bf1f4c699fc38d923be2b3e28936ef1f296dde6d10634095125e86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page