bundle.core.browser =================== .. py:module:: bundle.core.browser Attributes ---------- .. autoapisummary:: bundle.core.browser.logger bundle.core.browser.T Classes ------- .. autoapisummary:: bundle.core.browser.BrowserType bundle.core.browser.Browser Module Contents --------------- .. py:data:: logger .. py:data:: T .. py:class:: BrowserType(*args, **kwds) Bases: :py:obj:`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 - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: CHROMIUM :value: 'chromium' .. py:attribute:: FIREFOX :value: 'firefox' .. py:attribute:: WEBKIT :value: 'webkit' .. py:class:: Browser(/, **data: Any) Bases: :py:obj:`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() .. py:attribute:: is_closed :type: bool :value: None .. py:attribute:: browser_type :type: BrowserType :value: None .. py:attribute:: headless :type: bool :value: None .. py:attribute:: browser :type: playwright.async_api.Browser | None :value: None .. py:attribute:: contexts :type: list[playwright.async_api.BrowserContext] :value: None .. py:method:: validate_browser_type(v: str | BrowserType) -> BrowserType .. py:method:: chromium(headless: bool = True, **kwargs) -> collections.abc.AsyncIterator[Self] :classmethod: :async: Context manager to instantiate a Chromium browser. .. py:method:: firefox(headless: bool = True, **kwargs) -> collections.abc.AsyncIterator[Self] :classmethod: :async: Context manager to instantiate a Firefox browser. .. py:method:: webkit(headless: bool = True, **kwargs) -> collections.abc.AsyncIterator[Self] :classmethod: :async: Context manager to instantiate a WebKit browser. .. py:method:: launch() -> Self :async: Launch the specified browser type. :returns: The current instance for method chaining. :rtype: Browser .. py:method:: new_context(*args, **kwargs) -> Self :async: Create a new browser context. :returns: The current instance for method chaining. :rtype: Browser .. py:method:: new_page(**context_kwargs) -> playwright.async_api.Page :async: Create a new page within a new browser context. :returns: A new Playwright Page object. :rtype: Page .. py:method:: close() -> Self :async: Close all browser contexts and the browser itself. :returns: The current instance for method chaining. :rtype: Browser .. py:class:: Table(row_selector: str, columns: list[Browser], model: type[T]) Bases: :py:obj:`bundle.core.data.Data`, :py:obj:`Generic`\ [\ :py:obj:`T`\ ] Table specification: CSS selector for rows, list of Column, and model to instantiate. .. py:attribute:: row_selector :type: str .. py:attribute:: columns :type: list[Browser] .. py:attribute:: model :type: type[T] .. py:method:: parse(row: playwright.async_api.ElementHandle) -> dict[str, Any] :async: .. py:class:: Column(/, **data: Any) Bases: :py:obj:`bundle.core.data.Data` One column: field name, CSS selector, parser type, and optional base_url for URL parsing. .. py:class:: Type(*args, **kwds) Bases: :py:obj:`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 - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: TEXT :value: 'text' .. py:attribute:: INT :value: 'int' .. py:attribute:: URL :value: 'url' .. py:attribute:: name :type: str .. py:attribute:: selector :type: str .. py:attribute:: parser_type :type: type .. py:attribute:: base_url :type: str | None :value: None .. py:method:: parse_text(cell: playwright.async_api.ElementHandle) -> str :async: .. py:method:: parse_int(cell: playwright.async_api.ElementHandle) -> int :async: .. py:method:: parse_url(cell: playwright.async_api.ElementHandle) -> str :async: .. py:method:: parse(cell: playwright.async_api.ElementHandle) -> Any :async: Dispatch to the appropriate parser based on parser_type. .. py:method:: extract_table(page: playwright.async_api.Page, table: Table[T]) -> list[T] :async: Wait for `table.row_selector`, parse each row via `table.parse()`, and build a list of `table.model` instances.