在自定义Web驱动程序安装位置中,Python WebdriverManager.install()不适用于EDGE

Python Webdrivermanager .install() does not work for edge in custom webdriver installation location(在自定义Web驱动程序安装位置中,Python WebdriverManager.install()不适用于EDGE)

本文介绍了在自定义Web驱动程序安装位置中,Python WebdriverManager.install()不适用于EDGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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".Driversedgedriver_win64msedgedriver.exe"
File "PATHmicrosoft.py", line 51, in __init__
super().__init__(path, log_level, print_first_line, cache_valid_range)
File "PATHwebdriver_managermanager.py", line 13, in __init__
log("====== WebDriver manager ======", level=log_level)
File "PATHwebdriver_managerlogger.py", line 25, in log
_init_logger(level, name, first_line, formatter)
File "PATHwebdriver_managerlogger.py", line 19, in _init_logger
_logger.setLevel(level)
File "PATHPython310liblogging\__init__.py", line 1443, in setLevel
self.level = _checkLevel(level)
File "PATHPython310liblogging\__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...

已修改DIVER_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("
")
                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("
".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

这篇关于在自定义Web驱动程序安装位置中,Python WebdriverManager.install()不适用于EDGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在自定义Web驱动程序安装位置中,Python WebdriverManager.install()不适用于EDGE

基础教程推荐