Source code for langchain.document_loaders.url_playwright
"""Loader that uses Playwright to load a page, then uses unstructured to load the html.
"""
import logging
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, List, Optional
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader
if TYPE_CHECKING:
    from playwright.async_api import Browser as AsyncBrowser
    from playwright.async_api import Page as AsyncPage
    from playwright.async_api import Response as AsyncResponse
    from playwright.sync_api import Browser, Page, Response
logger = logging.getLogger(__name__)
[docs]class PlaywrightEvaluator(ABC):
    """Abstract base class for all evaluators.
    Each evaluator should take a page, a browser instance, and a response
    object, process the page as necessary, and return the resulting text.
    """
[docs]    @abstractmethod
    def evaluate(self, page: "Page", browser: "Browser", response: "Response") -> str:
        """Synchronously process the page and return the resulting text.
        Args:
            page: The page to process.
            browser: The browser instance.
            response: The response from page.goto().
        Returns:
            text: The text content of the page.
        """
        pass
[docs]    @abstractmethod
    async def evaluate_async(
        self, page: "AsyncPage", browser: "AsyncBrowser", response: "AsyncResponse"
    ) -> str:
        """Asynchronously process the page and return the resulting text.
        Args:
            page: The page to process.
            browser: The browser instance.
            response: The response from page.goto().
        Returns:
            text: The text content of the page.
        """
        pass