44from langchain_core .documents import Document
55import aiohttp
66import async_timeout
7- from selenium import webdriver
8- from selenium .webdriver .chrome .options import Options as ChromeOptions
97from typing import Union
108from ..utils import Proxy , dynamic_import , get_logger , parse_or_search_proxy
119
@@ -90,7 +88,10 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
9088 Returns:
9189 str: The scraped HTML content or an error message if an exception occurs.
9290 """
93- import undetected_chromedriver as uc
91+ try :
92+ import undetected_chromedriver as uc
93+ except ImportError :
94+ raise ImportError ("undetected_chromedriver is required for ChromiumLoader. Please install it with `pip install undetected-chromedriver`." )
9495
9596 logger .info (f"Starting scraping with { self .backend } ..." )
9697 results = ""
@@ -102,6 +103,7 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
102103 # Handling browser selection
103104 if self .backend == "selenium" :
104105 if self .browser_name == "chromium" :
106+ from selenium .webdriver .chrome .options import Options as ChromeOptions
105107 options = ChromeOptions ()
106108 options .headless = self .headless
107109 # Initialize undetected chromedriver for Selenium
@@ -112,6 +114,7 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
112114 break
113115 elif self .browser_name == "firefox" :
114116 from selenium .webdriver .firefox .options import Options as FirefoxOptions
117+ from selenium import webdriver
115118 options = FirefoxOptions ()
116119 options .headless = self .headless
117120 # Initialize undetected Firefox driver (if required)
0 commit comments