我目前正在 VS 代碼上使用 Jupyter notebook。但是我找不到Chromedriver 94.0.4606.61版本的chromedriver.exe檔案的路徑。我搜索了一整天,仍然找不到解決方案。我從 StackOverflow 上提出的上一個問題中得到了這些代碼的一些行:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
from selenium.webdriver.chrome.service import Service
service=Service(r'C:/path/to/Users/User/.wdm/drivers/chromedriver/win32/94.0.4606.61')
driver=webdriver.Chrome(service=service)
我試圖解決棄用的問題C:\Users\User\AppData\Local\Temp/ipykernel_17908/1503906442.py:1: DeprecationWarning: executable_path has been deprecated, please pass in a Service object,因此,我試圖找到Chromedriver.exe
當我下定決心棄用的問題,與這行代碼我輸入發生其他錯誤(如上圖所示): driver=webdriver.Chrome(service=service),
然后是來自 VS Code 的錯誤訊息:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\common\service.py in start(self)
73 cmd.extend(self.command_line_args())
---> 74 self.process = subprocess.Popen(cmd, env=self.env,
75 close_fds=system() != 'Windows',
C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask)
950
--> 951 self._execute_child(args, executable, preexec_fn, close_fds,
952 pass_fds, cwd, env,
C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session)
1419 try:
-> 1420 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
1421 # no special security
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17908/1442944818.py in <module>
----> 1 driver=webdriver.Chrome(service=service)
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\chrome\webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
67 service = Service(executable_path, port, service_args, service_log_path)
68
---> 69 super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
70 port, options,
71 service_args, desired_capabilities,
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\chromium\webdriver.py in __init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
88
89 self.service = service
---> 90 self.service.start()
91
92 try:
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\common\service.py in start(self)
82 except OSError as err:
83 if err.errno == errno.ENOENT:
---> 84 raise WebDriverException(
85 "'%s' executable needs to be in PATH. %s" % (
86 os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: '94.0.4606.61' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
Also, when I tried to run these codes(as shown below), deprecation issue and FileNotFoundError occurred simultaneously:
import time
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver')
I found this website saying that "chromedriver(.exe)" does not appear in Solution Explorer, but it is copied to the output folder from the package source folder when the build process. What does it mean?
I'm at my wit's end. Anyone got an idea to resolve this issue, please? *I am using Windows and Chrome version 94
Edit: I found some tips in this video:How To Fix -Executable path has been deprecated please pass in a Service object in Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service(executable_path="C:/Users/User/.wdm/drivers/chromedriver/win32/94.0.4606.61")
driver = webdriver.Chrome(Service = s)
However,driver = webdriver.Chrome(Service = s) is giving TypeError
------------------------------------------------------------------------
---
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11848/787057698.py in <module>
----> 1 driver = webdriver.Chrome(Service = s)
TypeError: __init__() got an unexpected keyword argument 'Service'
uj5u.com熱心網友回復:
像這樣嘗試:
import selenium
from selenium import webdriver
PATH = "r'C:/path/to/Users/User/.wdm/drivers/chromedriver/win32/94.0.4606.61'"
driver = webdriver.Chrome(PATH)
uj5u.com熱心網友回復:
你可以在這里找到它們
https://chromedriver.chromium.org/downloads
因為你的 Chrome 版本是 94 所以你需要下載這個
https://chromedriver.storage.googleapis.com/94.0.4606.61/chromedriver_win32.zip
放入也許 C 驅動程式并提供類似的路徑
import selenium
from selenium import webdriver
PATH = r"C:/chromedriver.exe"
driver = webdriver.Chrome(PATH)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/315575.html
標籤:python selenium 硒网络驱动程序 硒铬驱动器
上一篇:如何點擊svg元素?
