bundle.core.browser

Attributes

Classes

BrowserType

Create a collection of name/value pairs.

Browser

Simplified asynchronous Playwright browser wrapper with dynamic configuration,

Module Contents

bundle.core.browser.logger
bundle.core.browser.T
class bundle.core.browser.BrowserType(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

CHROMIUM = 'chromium'
FIREFOX = 'firefox'
WEBKIT = 'webkit'
class bundle.core.browser.Browser(/, **data: Any)[source]

Bases: bundle.core.entity.Entity

Simplified asynchronous Playwright browser wrapper with dynamic configuration, chainable methods, and robust error handling.

Example Usage:
async with Browser.chromium(headless=False) as browser:

page = await browser.new_page()

is_closed: bool = None
browser_type: BrowserType = None
headless: bool = None
browser: playwright.async_api.Browser | None = None
contexts: list[playwright.async_api.BrowserContext] = None
validate_browser_type(v: str | BrowserType) BrowserType[source]
classmethod chromium(headless: bool = True, **kwargs) collections.abc.AsyncIterator[Self][source]
Async:

Context manager to instantiate a Chromium browser.

classmethod firefox(headless: bool = True, **kwargs) collections.abc.AsyncIterator[Self][source]
Async:

Context manager to instantiate a Firefox browser.

classmethod webkit(headless: bool = True, **kwargs) collections.abc.AsyncIterator[Self][source]
Async:

Context manager to instantiate a WebKit browser.

async launch() Self[source]

Launch the specified browser type.

Returns:

The current instance for method chaining.

Return type:

Browser

async new_context(*args, **kwargs) Self[source]

Create a new browser context.

Returns:

The current instance for method chaining.

Return type:

Browser

async new_page(**context_kwargs) playwright.async_api.Page[source]

Create a new page within a new browser context.

Returns:

A new Playwright Page object.

Return type:

Page

async close() Self[source]

Close all browser contexts and the browser itself.

Returns:

The current instance for method chaining.

Return type:

Browser

class Table(row_selector: str, columns: list[Browser], model: type[T])[source]

Bases: bundle.core.data.Data, Generic[T]

Table specification: CSS selector for rows, list of Column, and model to instantiate.

row_selector: str
columns: list[Browser]
model: type[T]
async parse(row: playwright.async_api.ElementHandle) dict[str, Any][source]
class Column(/, **data: Any)[source]

Bases: bundle.core.data.Data

One column: field name, CSS selector, parser type, and optional base_url for URL parsing.

class Type(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

TEXT = 'text'
INT = 'int'
URL = 'url'
name: str
selector: str
parser_type: type
base_url: str | None = None
async parse_text(cell: playwright.async_api.ElementHandle) str[source]
async parse_int(cell: playwright.async_api.ElementHandle) int[source]
async parse_url(cell: playwright.async_api.ElementHandle) str[source]
async parse(cell: playwright.async_api.ElementHandle) Any[source]

Dispatch to the appropriate parser based on parser_type.

async extract_table(page: playwright.async_api.Page, table: Table[T]) list[T][source]

Wait for table.row_selector, parse each row via table.parse(), and build a list of table.model instances.