Skip to content

Commit

Permalink
fix: selenium import in ChromiumLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
PeriniM committed Jan 5, 2025
1 parent 927c99b commit e374e05
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions scrapegraphai/docloaders/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from langchain_core.documents import Document
import aiohttp
import async_timeout
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from typing import Union
from ..utils import Proxy, dynamic_import, get_logger, parse_or_search_proxy

Expand Down Expand Up @@ -90,7 +88,10 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
Returns:
str: The scraped HTML content or an error message if an exception occurs.
"""
import undetected_chromedriver as uc
try:
import undetected_chromedriver as uc
except ImportError:
raise ImportError("undetected_chromedriver is required for ChromiumLoader. Please install it with `pip install undetected-chromedriver`.")

logger.info(f"Starting scraping with {self.backend}...")
results = ""
Expand All @@ -102,6 +103,7 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
# Handling browser selection
if self.backend == "selenium":
if self.browser_name == "chromium":
from selenium.webdriver.chrome.options import Options as ChromeOptions
options = ChromeOptions()
options.headless = self.headless
# Initialize undetected chromedriver for Selenium
Expand All @@ -112,6 +114,7 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
break
elif self.browser_name == "firefox":
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium import webdriver
options = FirefoxOptions()
options.headless = self.headless
# Initialize undetected Firefox driver (if required)
Expand Down

0 comments on commit e374e05

Please sign in to comment.