agentbrowser


Nameagentbrowser JSON
Version 0.2.2 PyPI version JSON
download
home_pagehttps://github.com/AutonomousResearchGroup/agentbrowser
SummaryA browser for your agent, built on Playwright.
upload_time2023-08-02 00:45:05
maintainer
docs_urlNone
authorMoon
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements playwright
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
A browser for your agent, built on Playwright.


[![Lint and Test](https://github.com/AutonomousResearchGroup/agentbrowser/actions/workflows/test.yml/badge.svg)](https://github.com/AutonomousResearchGroup/agentbrowser/actions/workflows/test.yml)
[![PyPI version](https://badge.fury.io/py/agentbrowser.svg)](https://badge.fury.io/py/agentbrowser)

# Installation

```bash
pip install agentbrowser
```

# Usage

## Importing into your project

```python
from agentbrowser import (
    get_browser,
    init_browser,
    navigate_to,
    get_body_html,
    get_body_text,
    get_document_html,
    create_page,
    close_page,
    evaluate_javascript,
)
```

## Quickstart

```python
from agentbrowser import (
    navigate_to,
    get_body_text,
)

# Navigate to a URL
page = navigate_to("https://google.com")

# Get the text from the page
text = get_body_text(page)

print(text)
```

## API Documentation

### `ensure_event_loop()`

Ensure that there is an event loop in the current thread. If no event loop exists, a new one is created and set for the current thread. This function returns the current event loop.

Example usage:

```python
loop = ensure_event_loop()
```

### `get_browser()`

Get a Playwright browser. If the browser doesn't exist, initializes a new one.

Example usage:

```python
browser = get_browser()
```

### `init_browser(headless=True, executable_path=None)`

Initialize a new Playwright browser.

Parameters:

- `headless`: Whether the browser should be run in headless mode, defaults to True.
- `executable_path`: Path to a Chromium or Chrome executable to run instead of the bundled Chromium.

Example usage:

```python
init_browser(headless=False, executable_path="/usr/bin/google-chrome")
```

### `create_page(site=None)`

Create a new page in the browser. If a site is provided, navigate to that site.

Parameters:

- `site`: URL to navigate to, defaults to None.

Example usage:

```python
page = create_page("https://www.example.com")
```

### `close_page(page)`

Close a page.

Parameters:

- `page`: The page to close.

Example usage:

```python
page = create_page("https://www.example.com")
close_page(page)
```

### `navigate_to(url, page, wait_until="domcontentloaded")`

Navigate to a URL in a page.

Parameters:

- `url`: The URL to navigate to.
- `page`: The page to navigate in.

Example usage:

```python
page = create_page()
navigate_to("https://www.example.com", page)
```

### `get_document_html(page)`

Get the HTML content of a page.

Parameters:

- `page`: The page to get the HTML from.

Example usage:

```python
page = create_page("https://www.example.com")
html = get_document_html(page)
print(html)
```

### `get_page_title(page)`

Get the title of a page.

Parameters:

- `page`: The page to get the title from.

Example usage:

```python
page = create_page("https://www.example.com")
title = get_page_title(page)
print(title)
```

### `get_body_text(page)`

Get the text content of a page's body.

Parameters:

- `page`: The page to get the text from.

Example usage:

```python
page = create_page("https://www.example.com")
text = get_body_text(page)
print(text)
```

### `get_body_html(page)`

Get the HTML content of a page's body.

Parameters:

- `page`: The page to get the HTML from.

Example usage:

```python
page = create_page("https://www.example.com")
body_html = get_body_html(page)
print(body_html)
```

### `screenshot_page(page)`

Get a screenshot of a page.

Parameters:

- `page`: The page to screenshot.

Example usage:

```python
page = create_page("https://www.example.com")
screenshot = screenshot_page(page)
with open("screenshot.png", "wb") as f:
    f.write(screenshot)
```

### `evaluate_javascript(code, page)`

Evaluate JavaScript code in a page.

Parameters:

- `code`: The JavaScript code to evaluate.
- `page`: The page to evaluate the code in.

Example usage:

```python
page = create_page("https://www.example.com")
result = evaluate_javascript("document.title", page)
print(result)
```

### `find_chrome()`

Find the Chrome executable. Returns the path to the Chrome executable, or None if it could not be found.

Example usage:

```python
chrome_path = find_chrome()
print(chrome_path)
```

# Contributions Welcome

If you like this library and want to contribute in any way, please feel free to submit a PR and I will review it. Please note that the goal here is simplicity and accesibility, using common language and few dependencies.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AutonomousResearchGroup/agentbrowser",
    "name": "agentbrowser",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Moon",
    "author_email": "shawmakesmagic@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ab/c0/e3e9b60fba78a7c786d3bc1cfdcca73221cfb31b462bc6d14e62d481a990/agentbrowser-0.2.2.tar.gz",
    "platform": null,
    "description": "\nA browser for your agent, built on Playwright.\n\n\n[![Lint and Test](https://github.com/AutonomousResearchGroup/agentbrowser/actions/workflows/test.yml/badge.svg)](https://github.com/AutonomousResearchGroup/agentbrowser/actions/workflows/test.yml)\n[![PyPI version](https://badge.fury.io/py/agentbrowser.svg)](https://badge.fury.io/py/agentbrowser)\n\n# Installation\n\n```bash\npip install agentbrowser\n```\n\n# Usage\n\n## Importing into your project\n\n```python\nfrom agentbrowser import (\n    get_browser,\n    init_browser,\n    navigate_to,\n    get_body_html,\n    get_body_text,\n    get_document_html,\n    create_page,\n    close_page,\n    evaluate_javascript,\n)\n```\n\n## Quickstart\n\n```python\nfrom agentbrowser import (\n    navigate_to,\n    get_body_text,\n)\n\n# Navigate to a URL\npage = navigate_to(\"https://google.com\")\n\n# Get the text from the page\ntext = get_body_text(page)\n\nprint(text)\n```\n\n## API Documentation\n\n### `ensure_event_loop()`\n\nEnsure that there is an event loop in the current thread. If no event loop exists, a new one is created and set for the current thread. This function returns the current event loop.\n\nExample usage:\n\n```python\nloop = ensure_event_loop()\n```\n\n### `get_browser()`\n\nGet a Playwright browser. If the browser doesn't exist, initializes a new one.\n\nExample usage:\n\n```python\nbrowser = get_browser()\n```\n\n### `init_browser(headless=True, executable_path=None)`\n\nInitialize a new Playwright browser.\n\nParameters:\n\n- `headless`: Whether the browser should be run in headless mode, defaults to True.\n- `executable_path`: Path to a Chromium or Chrome executable to run instead of the bundled Chromium.\n\nExample usage:\n\n```python\ninit_browser(headless=False, executable_path=\"/usr/bin/google-chrome\")\n```\n\n### `create_page(site=None)`\n\nCreate a new page in the browser. If a site is provided, navigate to that site.\n\nParameters:\n\n- `site`: URL to navigate to, defaults to None.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\n```\n\n### `close_page(page)`\n\nClose a page.\n\nParameters:\n\n- `page`: The page to close.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\nclose_page(page)\n```\n\n### `navigate_to(url, page, wait_until=\"domcontentloaded\")`\n\nNavigate to a URL in a page.\n\nParameters:\n\n- `url`: The URL to navigate to.\n- `page`: The page to navigate in.\n\nExample usage:\n\n```python\npage = create_page()\nnavigate_to(\"https://www.example.com\", page)\n```\n\n### `get_document_html(page)`\n\nGet the HTML content of a page.\n\nParameters:\n\n- `page`: The page to get the HTML from.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\nhtml = get_document_html(page)\nprint(html)\n```\n\n### `get_page_title(page)`\n\nGet the title of a page.\n\nParameters:\n\n- `page`: The page to get the title from.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\ntitle = get_page_title(page)\nprint(title)\n```\n\n### `get_body_text(page)`\n\nGet the text content of a page's body.\n\nParameters:\n\n- `page`: The page to get the text from.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\ntext = get_body_text(page)\nprint(text)\n```\n\n### `get_body_html(page)`\n\nGet the HTML content of a page's body.\n\nParameters:\n\n- `page`: The page to get the HTML from.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\nbody_html = get_body_html(page)\nprint(body_html)\n```\n\n### `screenshot_page(page)`\n\nGet a screenshot of a page.\n\nParameters:\n\n- `page`: The page to screenshot.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\nscreenshot = screenshot_page(page)\nwith open(\"screenshot.png\", \"wb\") as f:\n    f.write(screenshot)\n```\n\n### `evaluate_javascript(code, page)`\n\nEvaluate JavaScript code in a page.\n\nParameters:\n\n- `code`: The JavaScript code to evaluate.\n- `page`: The page to evaluate the code in.\n\nExample usage:\n\n```python\npage = create_page(\"https://www.example.com\")\nresult = evaluate_javascript(\"document.title\", page)\nprint(result)\n```\n\n### `find_chrome()`\n\nFind the Chrome executable. Returns the path to the Chrome executable, or None if it could not be found.\n\nExample usage:\n\n```python\nchrome_path = find_chrome()\nprint(chrome_path)\n```\n\n# Contributions Welcome\n\nIf you like this library and want to contribute in any way, please feel free to submit a PR and I will review it. Please note that the goal here is simplicity and accesibility, using common language and few dependencies.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A browser for your agent, built on Playwright.",
    "version": "0.2.2",
    "project_urls": {
        "Homepage": "https://github.com/AutonomousResearchGroup/agentbrowser"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b4fc10a1af50f0f778ecaba44f415922582c9ba9ff3cffb048587785b25e76e",
                "md5": "f2ed56dbafcaf9eeb0d75ef5ff0066db",
                "sha256": "24c5a10b1226eac6a40b345bb4222ee5df6d240e45da539abb5d4e3e76f8887c"
            },
            "downloads": -1,
            "filename": "agentbrowser-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f2ed56dbafcaf9eeb0d75ef5ff0066db",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7208,
            "upload_time": "2023-08-02T00:45:03",
            "upload_time_iso_8601": "2023-08-02T00:45:03.209066Z",
            "url": "https://files.pythonhosted.org/packages/4b/4f/c10a1af50f0f778ecaba44f415922582c9ba9ff3cffb048587785b25e76e/agentbrowser-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abc0e3e9b60fba78a7c786d3bc1cfdcca73221cfb31b462bc6d14e62d481a990",
                "md5": "c62a4ae2a34bded97d75dd784bb8ec36",
                "sha256": "a66cbc7c8aa4fe6434c6b0eb3f2b3cbff9bebab6c7f6e03013e5f23c6eec0042"
            },
            "downloads": -1,
            "filename": "agentbrowser-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c62a4ae2a34bded97d75dd784bb8ec36",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7040,
            "upload_time": "2023-08-02T00:45:05",
            "upload_time_iso_8601": "2023-08-02T00:45:05.099478Z",
            "url": "https://files.pythonhosted.org/packages/ab/c0/e3e9b60fba78a7c786d3bc1cfdcca73221cfb31b462bc6d14e62d481a990/agentbrowser-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-02 00:45:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AutonomousResearchGroup",
    "github_project": "agentbrowser",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "playwright",
            "specs": []
        }
    ],
    "lcname": "agentbrowser"
}
        
Elapsed time: 0.12971s