使用selenium時出現 " FileNotFoundError: [WinError 2] 系統找不到指定的文件。" 的解決辦法。


python代碼:

 1 from selenium import webdriver
 2 
 3 
 4 def base_driver():
 5     driver = webdriver.Chrome()
 6     driver.maximize_window()
 7     driver.get("https://www.baidu.com")
 8     return driver
 9 
10 
11 if __name__ == '__main__':
12     base_driver()

報錯信息:

1 Traceback (most recent call last):
2   File "E:\練習項目代碼\project--python\data_system\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
3     self.process = subprocess.Popen(cmd, env=self.env,
4   File "D:\software\python\lib\subprocess.py", line 854, in __init__
5     self._execute_child(args, executable, preexec_fn, close_fds,
6   File "D:\software\python\lib\subprocess.py", line 1307, in _execute_child
7     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
8 FileNotFoundError: [WinError 2] 系統找不到指定的文件。

 

錯誤的原因提示系統找不到指定的文件,導致錯誤的原因,找不到chromedriver

解決方法:

1。修改代碼,把chromedrive安裝路徑填入,如下:

driver = webdriver.Chrome("C:/Program Files/Google/Chrome/Application/chromedriver.exe")

2。把chromedriver.exe的文件放在python安裝路徑中,如:D:\software\python\chromedriver.exe

3。修改電腦中Python安裝目錄中的lib下的subprocess.py文件中__init__中的shell=False。(感覺沒什么用)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM