selenium - chromedriver 可执行文件需要位于 PATH 中[重复]
- 2025-03-19 08:57:00
- admin 原创
- 67
问题描述:
错误信息:
‘chromedriver’ 可执行文件需要位于 PATH 中
我尝试在 pycharm 中使用 selenium 编写脚本,但出现上述错误。我已经将 selenium 链接到 pycharm,如这里所示(最新且最新)。
我是 selenium 新手,chromedriver 不是在“selenium”文件夹中吗?如果不在,我在哪里可以找到它并将其添加到路径中?
顺便说一句,我尝试在 cmd 中输入“chromedriver”,但是它没有被识别为内部或外部命令。
错误如下图所示:
Traceback (most recent call last):
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsubprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsubprocess.py", line 1224, in _execute_child
startupinfo)
PermissionError: [WinError 5] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/sebastian/PycharmProjects/web/bot.py", line 10, in <module>
browser = webdriver.Chrome("C:/Users/sebastian/desktop/selenium-3.0.1")
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsite-packagesseleniumwebdriverchromewebdriver.py", line 62, in __init__
self.service.start()
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 76, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'selenium-3.0.1' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x01EDEAF0>>
Traceback (most recent call last):
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 163, in __del__
self.stop()
File "C:UserssebastianAppDataLocalProgramsPythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
解决方案 1:
您可以在此处下载 ChromeDriver:
https://sites.google.com/chromium.org/driver/
那么你有多个选择:
将其添加到您的系统
path
将其放在与你的 Python 脚本相同的目录中
直接通过以下方式指定位置
executable_path
driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')
解决方案 2:
尝试一下:
pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
解决方案 3:
另一种方法是下载并解压 chromedriver,并将“chromedriver.exe”放在 C:\Python27\Scripts 中,然后您不需要提供驱动程序的路径,只需
driver= webdriver.Chrome()
会起作用
解决方案 4:
来自 2020 年的答案。以下代码解决了这个问题。许多刚接触 selenium 的人似乎必须完成这一步。安装 chromedriver 并将其放在桌面上的文件夹中。还要确保将 selenium python 项目放在与 chrome 驱动程序所在的同一文件夹中。
根据您的计算机更改 USER_NAME 和 FOLDER。
对于 Windows
driver = webdriver.Chrome(r"C:UsersUSER_NAMEDesktopFOLDERchromedriver")
对于Linux / Mac
driver = webdriver.Chrome("/home/USER_NAME/FOLDER/chromedriver")
解决方案 5:
不要在文件路径中包含“.exe”。
例如:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='path/to/folder/chromedriver')
解决方案 6:
试试这个:
driver = webdriver.Chrome(ChromeDriverManager().install())
相关推荐
热门文章
项目管理软件有哪些?
热门标签
曾咪二维码
扫码咨询,免费领取项目管理大礼包!
云禅道AD