From 2f912b0b955d2ec83ca3f8b44680cebd21cddd87 Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 00:39:20 +0530 Subject: [PATCH 1/2] Update browser.py changes made to find the chrome path across the os. --- sources/browser.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sources/browser.py b/sources/browser.py index ea10fec..9d959a9 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -6,6 +6,7 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException, WebDriverException import time +import os from bs4 import BeautifulSoup import markdownify import logging @@ -23,6 +24,12 @@ class Browser: self.anticaptcha = "https://chrome.google.com/webstore/detail/nopecha-captcha-solver/dknlfmjaanfblgfdfebhijalfmhmjjjo/related" try: chrome_options = Options() + chrome_path = self.get_chrome_path() + + if not chrome_path: + raise FileNotFoundError("Google Chrome not found. Please install it.") + chrome_options.binary_location = chrome_path + if headless: chrome_options.add_argument("--headless") chrome_options.add_argument("--disable-gpu") @@ -34,6 +41,25 @@ class Browser: self.logger.info("Browser initialized successfully") except Exception as e: raise Exception(f"Failed to initialize browser: {str(e)}") + + @staticmethod + def get_chrome_path(): + if sys.platform.startswith("win"): + paths = [ + "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", + "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", + os.path.join(os.environ.get("LOCALAPPDATA", ""), "Google\\Chrome\\Application\\chrome.exe") # User install + ] + elif sys.platform.startswith("darwin"): # macOS + paths = ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"] + else: # Linux + paths = ["/usr/bin/google-chrome", "/usr/bin/chromium-browser", "/usr/bin/chromium"] + + for path in paths: + if os.path.exists(path) and os.access(path, os.X_OK): # Check if executable + return path + return None + def go_to(self, url): """Navigate to a specified URL.""" @@ -185,4 +211,4 @@ if __name__ == "__main__": links = browser.get_navigable() print("\nNavigable Links:", links) finally: - browser.close() \ No newline at end of file + browser.close() From 3e7d40c4f66d6723050e40f0c58f358e5a384b75 Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 00:53:19 +0530 Subject: [PATCH 2/2] Update browser.py finding the chromepath automatically. --- sources/browser.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sources/browser.py b/sources/browser.py index 9d959a9..9a5acd3 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -7,6 +7,7 @@ from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException, WebDriverException import time import os +import shutil from bs4 import BeautifulSoup import markdownify import logging @@ -35,7 +36,12 @@ class Browser: chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") - self.driver = webdriver.Chrome(options=chrome_options) + # Automatically find ChromeDriver path + chromedriver_path = shutil.which("chromedriver") + if not chromedriver_path: + raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.") + service = Service(chromedriver_path) + self.driver = webdriver.Chrome(service=service, options=chrome_options) self.wait = WebDriverWait(self.driver, 10) self.logger = logging.getLogger(__name__) self.logger.info("Browser initialized successfully")