在 Ubuntu 中安装 Selenium 并将 geckodriver 添加到路径后,我在运行时收到此错误
from selenium import webdriver
driver = webdriver.Firefox()
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 20] Not a directory
这是怎么回事?
编辑:使用 chromedriver 而不是 geckodriver 解决了。
原文由 User 发布,翻译遵循 CC BY-SA 4.0 许可协议
有同样的问题。有两种方法可以为我解决这个问题:
在 webdriver 中添加 executable_path arg:
第二种方法是使用导出添加包含 geckodriver 的文件夹(仅文件夹,而不是 geckodriver):