Python - Ubuntu OSError 中的 Selenium:\[Errno 20\] 不是目录

新手上路,请多包涵

在 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 许可协议

阅读 376
1 个回答

有同样的问题。有两种方法可以为我解决这个问题:

在 webdriver 中添加 executable_path arg:

 driver = webdriver.Firefox(executable_path='/path/to/geckodriver')

第二种方法是使用导出添加包含 geckodriver 的文件夹(仅文件夹,而不是 geckodriver):

 $ export PATH=$PATH:/path/to/

原文由 Poloq 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题