4
4
from langchain_core .documents import Document
5
5
import aiohttp
6
6
import async_timeout
7
- from selenium import webdriver
8
- from selenium .webdriver .chrome .options import Options as ChromeOptions
9
7
from typing import Union
10
8
from ..utils import Proxy , dynamic_import , get_logger , parse_or_search_proxy
11
9
@@ -90,7 +88,10 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
90
88
Returns:
91
89
str: The scraped HTML content or an error message if an exception occurs.
92
90
"""
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`." )
94
95
95
96
logger .info (f"Starting scraping with { self .backend } ..." )
96
97
results = ""
@@ -102,6 +103,7 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
102
103
# Handling browser selection
103
104
if self .backend == "selenium" :
104
105
if self .browser_name == "chromium" :
106
+ from selenium .webdriver .chrome .options import Options as ChromeOptions
105
107
options = ChromeOptions ()
106
108
options .headless = self .headless
107
109
# Initialize undetected chromedriver for Selenium
@@ -112,6 +114,7 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
112
114
break
113
115
elif self .browser_name == "firefox" :
114
116
from selenium .webdriver .firefox .options import Options as FirefoxOptions
117
+ from selenium import webdriver
115
118
options = FirefoxOptions ()
116
119
options .headless = self .headless
117
120
# Initialize undetected Firefox driver (if required)
0 commit comments