Skip to content

Web loader

WebLoader

Bases: BaseTextLoader

Source code in griptape/loaders/web_loader.py
@define
class WebLoader(BaseTextLoader):
    web_scraper_driver: BaseWebScraperDriver = field(
        default=Factory(lambda: TrafilaturaWebScraperDriver()), kw_only=True
    )

    def load(self, source: str, *args, **kwargs) -> ErrorArtifact | list[TextArtifact]:
        try:
            single_chunk_text_artifact = self.web_scraper_driver.scrape_url(source)
            return self._text_to_artifacts(single_chunk_text_artifact.value)
        except Exception as e:
            return ErrorArtifact(f"Error loading from source: {source}", exception=e)

web_scraper_driver: BaseWebScraperDriver = field(default=Factory(lambda: TrafilaturaWebScraperDriver()), kw_only=True) class-attribute instance-attribute

load(source, *args, **kwargs)

Source code in griptape/loaders/web_loader.py
def load(self, source: str, *args, **kwargs) -> ErrorArtifact | list[TextArtifact]:
    try:
        single_chunk_text_artifact = self.web_scraper_driver.scrape_url(source)
        return self._text_to_artifacts(single_chunk_text_artifact.value)
    except Exception as e:
        return ErrorArtifact(f"Error loading from source: {source}", exception=e)