尝试在ipython笔记本中使用Selenium打开Firefox时出错。我环顾四周,发现了类似的错误,但没有什么能与我得到的错误完全匹配。有人知道问题可能是什么以及我如何解决它?我正在使用Firefox 22。
我输入的代码如下:
from selenium import webdriver
driver = webdriver.Firefox()
代码返回的错误如下:
WindowsError Traceback (most recent call last)
<ipython-input-7-fd567e24185f> in <module>()
----> 1 driver = webdriver.Firefox()
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy)
56 RemoteWebDriver.__init__(self,
57 command_executor=ExtensionConnection("127.0.0.1", self.profile,
---> 58 self.binary, timeout),
59 desired_capabilities=capabilities)
60 self._is_remote = False
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\extension_connection.pyc in __init__(self, host, firefox_profile, firefox_binary, timeout)
45 self.profile.add_extension()
46
---> 47 self.binary.launch_browser(self.profile)
48 _URL = "http://%s:%d/hub" % (HOST, PORT)
49 RemoteConnection.__init__(
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.pyc in launch_browser(self, profile)
45 self.profile = profile
46
---> 47 self._start_from_profile_path(self.profile.path)
48 self._wait_until_connectable()
49
C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_binary.pyc in _start_from_profile_path(self, path)
71
72 Popen(command, stdout=PIPE, stderr=STDOUT,
---> 73 env=self._firefox_env).communicate()
74 command[1] = '-foreground'
75 self.process = Popen(
C:\Anaconda\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
677 p2cread, p2cwrite,
678 c2pread, c2pwrite,
--> 679 errread, errwrite)
680
681 if mswindows:
C:\Anaconda\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
894 env,
895 cwd,
--> 896 startupinfo)
897 except pywintypes.error, e:
898 # Translate pywintypes.error to WindowsError, which is
WindowsError: [Error 2] The system cannot find the file specified
答案 0 :(得分:28)
在初始化Firefox()
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)
FirefoxDriver寻找的默认路径为%PROGRAMFILES%\Mozilla Firefox\firefox.exe
。见FirefoxDriver
或者将Firefox二进制文件的路径添加到Windows“PATH。
”答案 1 :(得分:2)
答案 2 :(得分:1)
要求:
这就是我要做的:
pip3安装硒
提取壁虎驱动程序
mv壁虎驱动程序/ usr / local / bin /
导出PATH = $ PATH:/ usr / local / bin / geckodriver
使用命令检查Xauthority->定位Xauthority
cd / home /您的用户/ Xauthority
小丑的根:.Xauthority
创建python代码:
从硒导入网络驱动程序
浏览器= webdriver.Firefox() browser.get('http:// localhost')
运行python脚本。
答案 3 :(得分:0)
当我设置环境变量export PYTHONDONTWRITEBYTECODE=1
以在每次测试运行时摆脱pyc文件时,我遇到了同样的错误。我能够通过更新selenium pip install --upgrade selenium
来恢复更改。 OSX(10.10)
答案 4 :(得分:0)
这是有用的:
public class Rep_Setting
{
DataBase db = new DataBase();
public Tbl_Setting Tools()
{
var qGetSetting = (from a in db.Tbl_Setting
select a).FirstOrDefault();
if(qGetSetting == null){ throw new Exception("Found no rows in the database table Tbl_Setting"); }
return qGetSetting;
}
}
答案 5 :(得分:0)
需要这两个包(ubuntu)!
apt-get update
apt-get install -y xorg xvfb firefox dbus-x11 xfonts-100dpi xfonts-75dpi xfonts-cyrillic
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
sudo apt install linuxbrew-wrapper
brew install geckodriver
对我来说也是使用chrome而不是firefox 查看本教程: https://christopher.su/2015/selenium-chromedriver-ubuntu/
答案 6 :(得分:0)
driver=webdriver.Firefox(executable_path="add geckodriver.exe",log_path=None)
答案 7 :(得分:0)
您需要安装geckodriver:
https://selenium-python.readthedocs.io/installation.html
只需下载它,解压缩,然后将其复制到您的python目录中即可。