Python Webdrivermanager .install() 不适用于自定义 webdriver 安装位置中的边缘

Python Webdrivermanager .install() does not work for edge in custom webdriver installation location

我使用 Webdrivermanager 来更新我的驱动程序。 但是对于 Edge 浏览器,我得到了错误。

elif preferred_browser == "Edge":
service = Edge_Service(EdgeChromiumDriverManager().install())
service.creationflags = CREATE_NO_WINDOW
driver = webdriver.Edge(service=service)

错误:

File "PATH", line 1168, in start
service = Edge_Service(EdgeChromiumDriverManager().install())#r".\Drivers\edgedriver_win64\msedgedriver.exe"
File "PATH\microsoft.py", line 51, in __init__
super().__init__(path, log_level, print_first_line, cache_valid_range)
File "PATH\webdriver_manager\manager.py", line 13, in __init__
log("====== WebDriver manager ======", level=log_level)
File "PATH\webdriver_manager\logger.py", line 25, in log
_init_logger(level, name, first_line, formatter)
File "PATH\webdriver_manager\logger.py", line 19, in _init_logger
_logger.setLevel(level)
File "PATH\Python310\lib\logging\__init__.py", line 1443, in setLevel
self.level = _checkLevel(level)
File "PATH\Python310\lib\logging\__init__.py", line 201, in _checkLevel
raise TypeError("Level not an integer or a valid string: %r"
TypeError: Level not an integer or a valid string: None

好吧,我编辑了管理器,以保存到另一个位置。但它确实适用于 Chrome 而 Firefox 为什么不适用于 edge...

修改后driver_cache.py:

    def save_file_to_cache(self, file: File, browser_version, driver_name, os_type, driver_version):
    for directory in os.listdir(r'./Drivers/') :
        if re.fullmatch('.*'+driver_name+'.*',directory):
            
            shutil.rmtree(r'./Drivers/'+directory)

            with open(r'./Drivers/drivers.json') as oldfile:
                data = oldfile.read().split("\n")
                oldfile.close()

                i = 0
                new_data = []
                while i < len(data):
                    if driver_name in data[i]:
                        i += 4
                        continue
                    new_data.append(data[i])
                    i += 1

            with open(r'./Drivers/drivers.json', 'w') as newfile:
                newfile.write("\n".join(new_data)) 

            data = yaml.load(open(r'./Drivers/drivers.json'),Loader=yaml.FullLoader)
            data = json.dumps(data)
            data = data.replace("'",'"')

            with open(r'./Drivers/drivers.json', 'w') as newfile:
                newfile.write(data) 


        path = r".\Drivers\" + driver_name + "_" + driver_version
        archive = save_file(file, path)
        files = archive.unpack(path)
        binary = self.__get_binary(files, driver_name)
        binary_path = os.path.join(path, binary)
        self.__save_metadata(browser_version, driver_name, os_type, driver_version, binary_path)
        log(f"Driver has been saved in cache [{path}]")
        return binary_path

修改后microsoft.py:

class EdgeChromiumDriverManager(DriverManager):
    def __init__(
        self,
        version="latest",
        os_type=utils.os_type(),
        #path=None,
        path=r".\Drivers",
        name="edgedriver",
        url="https://msedgedriver.azureedge.net",       
        latest_release_url="https://msedgedriver.azureedge.net/ LATEST_RELEASE",
        log_level=None,
        print_first_line=None,
        cache_valid_range=1,
    ):
        super().__init__(path, log_level, print_first_line, cache_valid_range)
        self.driver = EdgeChromiumDriver(
            version=version,
            os_type=os_type,
            name=name,
            url=url,
            latest_release_url=latest_release_url,
        )

只是为了比较编辑和工作 chrome.py:

class ChromeDriverManager(DriverManager):
    def __init__(self, version="latest",
                 os_type=utils.os_type(),
                 #path=None,
                 path=r".\Drivers",
                 name="chromedriver",
                 url="https://chromedriver.storage.googleapis.com",   latest_release_url="https://chromedriver.storage.googleapis.com/LATEST_RELEASE",
                 chrome_type=ChromeType.GOOGLE,
                 log_level=logging.INFO,
                 print_first_line=True,
                 cache_valid_range=1):
            super().__init__(path, log_level=log_level, print_first_line=print_first_line,
                     cache_valid_range=cache_valid_range)

    self.driver = ChromeDriver(name=name,
                               version=version,
                               os_type=os_type,
                               url=url,
                               latest_release_url=latest_release_url,
                               chrome_type=chrome_type)

对不起,我不知道:(

最好的问候 克里斯蒂安

好的,

这是 Webdrivermanager 的记录器问题。

对于 microsoft.py,我必须导入日志记录并对 log_level 进行一些更改:

class EdgeChromiumDriverManager(DriverManager):
def __init__(
    self,
    version="latest",
    os_type=utils.os_type(),
    #path=None,
    path=r".\Drivers",
    name="edgedriver",
    url="https://msedgedriver.azureedge.net",
    latest_release_url="https://msedgedriver.azureedge.net/LATEST_RELEASE",
    log_level=logging.INFO,
    print_first_line=None,
    cache_valid_range=1,
):
    super().__init__(path, log_level, print_first_line, cache_valid_range)
    self.driver = EdgeChromiumDriver(
        version=version,
        os_type=os_type,
        name=name,
        url=url,
        latest_release_url=latest_release_url,
    )

编辑:

我创建了一个custom_webdriver_manager

我遇到了同样的问题,并且找到了更简单的解决方法。如果我在构建 EdgeChromiumDriverManager 时指定日志级别,那么我不会收到错误:

import logging    
service = Edge_Service(EdgeChromiumDriverManager(log_level=logging.ERROR).install())