为什么我不能用硒运行这个简单的例子?

时间:2016-04-13 13:52:46

标签: python selenium

脚本是:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.python.org")

然后出来了:

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/GeniusV/Documents/pythonProject/untitled/hj.py
Traceback (most recent call last):
  File "/Users/GeniusV/Documents/pythonProject/untitled/hj.py", line 5, in <module>
    driver = webdriver.Firefox()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 103, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 67, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 90, in _start_from_profile_path
    env=self._firefox_env)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception

OSError: [Errno 2] No such file or directory

我真的不明白为什么,这是我的python还是selenium的问题?

1 个答案:

答案 0 :(得分:1)

听起来像兼容性问题

确保您使用的是最新的硒:

pip install --upgrade selenium

安装了最新的Firefox。