diff --git a/undetected_chromedriver/__init__.py b/undetected_chromedriver/__init__.py index 87ba76a..96f108a 100644 --- a/undetected_chromedriver/__init__.py +++ b/undetected_chromedriver/__init__.py @@ -17,11 +17,12 @@ by UltrafunkAmsterdam (https://github.com/ultrafunkamsterdam) from __future__ import annotations -__version__ = "3.5.1a" +__version__ = "3.5.2" import json import logging import os +import pathlib import re import shutil import subprocess @@ -372,6 +373,18 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver): browser_executable_path or find_chrome_executable() ) + if not options.binary_location or not \ + pathlib.Path(options.binary_location).exists(): + raise FileNotFoundError( + "\n---------------------\n" + "Could not determine browser executable." + "\n---------------------\n" + "Make sure your browser is installed in the default location (path).\n" + "If you are sure about the browser executable, you can specify it using\n" + "the `browser_executable_path='{}` parameter.\n\n" + .format("/path/to/browser/executable" if IS_POSIX else "c:/path/to/your/browser.exe") + ) + self._delay = 3 self.user_data_dir = user_data_dir @@ -877,8 +890,6 @@ def find_chrome_executable(): if item is not None: for subitem in ( "Google/Chrome/Application", - "Google/Chrome Beta/Application", - "Google/Chrome Canary/Application", ): candidates.add(os.sep.join((item, subitem, "chrome.exe"))) for candidate in candidates: diff --git a/undetected_chromedriver/patcher.py b/undetected_chromedriver/patcher.py index d7d62b0..4c062f6 100644 --- a/undetected_chromedriver/patcher.py +++ b/undetected_chromedriver/patcher.py @@ -111,18 +111,16 @@ class Patcher(object): Returns: """ - # if self.user_multi_procs and \ - # self.user_multi_procs != -1: - # # -1 being a skip value used later in this block - # p = pathlib.Path(self.data_path) if self.user_multi_procs: with Lock(): - files = list(p.rglob("*chromedriver*?")) - for file in files: - if self.is_binary_patched(file): - self.executable_path = str(file) - return True + files = list(p.rglob("*chromedriver*")) + most_recent = max(files, key=lambda f: f.stat().st_mtime) + files.remove(most_recent) + list(map(lambda f: f.unlink(), files)) + if self.is_binary_patched(most_recent): + self.executable_path = str(most_recent) + return True if executable_path: self.executable_path = executable_path