在ipython notebooks中使用Selenium打开Firefox时出错,我用的是火狐浏览器,代码如下:
from selenium import webdriver
driver = webdriver.Firefox()
报错信息如下:
The error the code returns is as follows:
WindowsError Traceback (most recent call last)
in ()
----> 1 driver = webdriver.Firefox()
解决方法:
尝试初始化Firefox()时指定Firefox二进制文件,默认路径FirefoxDriver在%PROGRAMFILES%\Mozilla Firefox\firefox.exe中。指定firefoxdriver或将Firefox二进制文件的路径添加到Windows路径。指定firefoxdriver路径的代码如下:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)