簡體   English   中英

Python Chromedriver WinError 2 與 Selenium

[英]Python Chromedriver WinError 2 with Selenium

我的代碼中出現以下錯誤:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", 
line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\subprocess.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 路徑無濟於事。 有趣的是,這個錯誤只是偶爾發生,但我還沒有找到一個模式。 這是我的 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)

更新:解決方案。 結果我定義了兩次驅動程序,刪除了一個定義,它似乎做得很好。 不確定為什么它會引發該特定錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM