如果你的selenium是3.X版本的,火狐浏览器需要geckodriver这个组件的支持,2.X版本则不需要。
使用selenium自动打开火狐浏览器错误提示:
Traceback (most recent call last):
File "/home/yanner/seleniumtest/sousuo.py", line 2, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
ubuntu系统,使用selenium3.X版本的,火狐浏览器需要下载geckodriver:
https://github.com/mozilla/geckodriver/releases
下载后直接解压,将解压后的文件geckodriver放入/usr/local/bin目录下(该目录是存放执行文件的)
打开终端输入以下命令:
su root (如出现su认证失败请点击看上一篇文章)
然后进入文件geckodriver存放的目录,将该文件复制到/usr/local/bin目录下
root@yanner-VirtualBox:/home/yanner# cd ruanjian
root@yanner-VirtualBox:/home/yanner/ruanjian# cp geckodriver /usr/local/bin/
root@yanner-VirtualBox:/home/yanner/ruanjian#
再次运行:
from selenium import webdriver
browser = webdriver.Firefox()
不再提示:'geckodriver' executable needs to be in PATH.