本文介绍了正在使用Python初始化MSEdge浏览器,获取TypeError:Level不是整数或有效字符串:无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试初始化MSedge浏览器,但遇到错误。
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
s=Service(EdgeChromiumDriverManager().install())
driver = webdriver.Edge(service=s)
driver.get('https://www.google.com')
错误声明:
TypeError Traceback (most recent call last)
<ipython-input-2-4e36192a99d3> in <module>
3 from webdriver_manager.microsoft import EdgeChromiumDriverManager
4
----> 5 s=Service(EdgeChromiumDriverManager().install())
6 driver = webdriver.Edge(service=s)
7 driver.maximize_window()
~Anaconda3libsite-packageswebdriver_managermicrosoft.py in __init__(self, version, os_type, path, name, url, latest_release_url, log_level, print_first_line, cache_valid_range)
49 cache_valid_range=1,
50 ):
---> 51 super().__init__(path, log_level, print_first_line, cache_valid_range)
52 self.driver = EdgeChromiumDriver(
53 version=version,
~Anaconda3libsite-packageswebdriver_managermanager.py in __init__(self, root_dir, log_level, print_first_line, cache_valid_range)
10 self.driver_cache = DriverCache(root_dir, cache_valid_range)
11 if os.environ.get('WDM_PRINT_FIRST_LINE', str(print_first_line)) == 'True':
---> 12 log("
", formatter='%(message)s', level=log_level)
13 log("====== WebDriver manager ======", level=log_level)
14
~Anaconda3libsite-packageswebdriver_managerlogger.py in log(text, level, name, first_line, formatter)
23 def log(text, level=logging.INFO, name="WDM", first_line=False, formatter='[%(name)s] - %(message)s'):
24 """Emitting the log message."""
---> 25 _init_logger(level, name, first_line, formatter)
26 loggers.get(name).info(text)
~Anaconda3libsite-packageswebdriver_managerlogger.py in _init_logger(level, name, first_line, formatter)
17 handler.setFormatter(formatter)
18 _logger.addHandler(handler)
---> 19 _logger.setLevel(level)
20 loggers[name] = _logger
21
~Anaconda3liblogging\__init__.py in setLevel(self, level)
1407 Set the logging level of this logger. level must be an int or a str.
1408 """
-> 1409 self.level = _checkLevel(level)
1410 self.manager._clear_cache()
1411
~Anaconda3liblogging\__init__.py in _checkLevel(level)
195 rv = _nameToLevel[level]
196 else:
--> 197 raise TypeError("Level not an integer or a valid string: %r" % level)
198 return rv
199
TypeError: Level not an integer or a valid string: None
推荐答案
这是WebDRIVER_MANAGER 3.5.2的问题。WebDRIVER_MANAGER的记录器有问题。详情请参考this issue和this pull request。
您可以根据拉取请求编辑WebDRIVER_MANAGER的源代码来修复该问题。您可以编辑webdriver_manager/microsoft.py
文件,添加import logging
并将log_level=None
更改为log_level=logging.INFO
。然后它就可以与Edge驱动程序很好地配合使用了。
这篇关于正在使用Python初始化MSEdge浏览器,获取TypeError:Level不是整数或有效字符串:无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!