我已经在MacOS上下载了Selenium和Chromedriver,但是似乎无法在我的IDLE Python Shell上执行:
driver = webdriver.Chrome()
错误消息返回:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1499, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
driver = webdriver.Chrome()
File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver'
executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
我试图将Chromedriver设置在正确的路径中,方法是将其放置在usr / local / bin中,并将其放置在所附图像的selenium文件夹中。但是,我不确定它是否在正确的位置,因为仍然会出现相同的错误。
我该如何解决?
非常感谢您!
答案 0 :(得分:0)
您知道,主要错误是您的chromedriver可执行文件不在PATH中。在Python脚本中执行以下操作以指定PATH:
import sys
path = '/path/to/your/chromedriver/executable'
sys.path.append(path)
# then continue your script
据我所知,chromedriver可执行文件不需要位于bin
目录中才能正常工作;您可以将其放置在任何地方,只要使用上面的代码指定程序可以在哪里找到它即可。