我的代码中出现以下错误:
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython38-32libsite-packagesseleniumwebdrivercommonservice.py",
line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:UsersuserAppDataLocalProgramsPythonPython38-32libsubprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:UsersuserAppDataLocalProgramsPythonPython38-32libsubprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
我尝试过更改PATH变量,更改chromedriver路径都没有用。有趣的是,这个错误只是偶尔发生,不过我还没有找到一个模式。这是我的彩色打印机定义:
options = Options()
options.headless = True
options.add_argument('--log-level=3')
chromepath = str(Path(os.getcwd()).parent) + r'chromedriver.exe'
driver = webdriver.Chrome(chromepath, options=options)
奇怪的是,它有时只起作用。将其设置为一个绝对路径,它应该可以正常工作。
chromepath = str(Path(os.getcwd()).parent) + r'chromedriver.exe'
print (chromepath) #set the output of this below
driver = webdriver.Chrome("abs path here", options=options)
更新:解决方案。事实证明,我定义了两次驱动程序,删除了一个定义,它似乎做得很好。但不确定它为什么会提出那个特定的错误。