编程语言
首页 > 编程语言> > 硒python绑定是否需要firefox

硒python绑定是否需要firefox

作者:互联网

嗨,我刚刚下载并安装了selenium,但是我无法确定如何使其正常工作,我正在使用以下示例进行测试….

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()         #this is where I hit the error
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()

我的计算机上没有安装firefox,这就是为什么它给我一个错误?
这是我尝试运行时收到的错误输出

Traceback (most recent call last):
  File "C:/Python27/test/helloworld.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 60, in __init__
    self.binary, timeout),
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
    env=self._firefox_env).communicate()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
    startupinfo)
WindowsError: [Error 87] The parameter is incorrect

解决方法:

下一行启动Firefox浏览器,因此是的,它需要安装Firefox.

driver = webdriver.Firefox()  

如果您没有安装Firefox,则可以改用其他浏览器:

webdriver.Opera
webdriver.Ie
webdriver.Chrome
...

看到

help(webdriver)

标签:firefox,selenium,selenium-webdriver,web-scraping,python
来源: https://codeday.me/bug/20191122/2062655.html