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

Use*_*ser 17 python ubuntu selenium

在Ubuntu中安装Selenium并在路径中添加geckodriver后,运行时出现此错误

from selenium import webdriver

driver = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?

编辑:解决使用chromedriver而不是geckodriver.

小智 34

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

在webdriver中添加executable_path arg:

driver = webdriver.Firefox(executable_path='/path/to/geckodriver')
Run Code Online (Sandbox Code Playgroud)

第二种方式是使用export添加包含geckodriver的文件夹(仅限文件夹,而不是geckodriver):

$ export PATH=$PATH:/path/to/
Run Code Online (Sandbox Code Playgroud)


小智 1

问题是您将“geckodriver”重命名为“wires”。

解决方案是将“geckodriver”添加到搜索路径,然后它应该可以工作。