Python Can';不要使用firefox驱动程序打开网站

Python Can';不要使用firefox驱动程序打开网站,python,python-3.x,selenium-webdriver,Python,Python 3.x,Selenium Webdriver,我正在尝试使用python和selenium登录一个网站。我觉得壁虎河有点问题。我已经安装了firefox和gecko驱动程序的最新版本,但仍然无法正常工作。 我试过以下方法。在我重新安装Windows之前,它可以正常工作,过去也可以: from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from sel

我正在尝试使用python和selenium登录一个网站。我觉得壁虎河有点问题。我已经安装了firefox和gecko驱动程序的最新版本,但仍然无法正常工作。 我试过以下方法。在我重新安装Windows之前,它可以正常工作,过去也可以:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("https://www.instagram.com/accounts/login/")

username =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']")))
password =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='password']")))
username.clear()
username.send_keys("My Username")
password.clear()
password.send_keys("My Password")
try:
    element = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//button[@type='submit']"))
    )
finally:
    element.click()

if len(driver.find_elements_by_xpath("//form[@id='slfErrorAlert']"))>0:
    # Element is present
    print("Not!")
else:
    # Element is not present
    print ("Logged IN!")
以下是错误:

>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> from selenium.webdriver.common.by import By
>>> from selenium.webdriver.support.ui import WebDriverWait
>>> from selenium.webdriver.support import expected_conditions as EC
>>>
>>> driver = webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

>>> driver.get("https://www.instagram.com/accounts/login/")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>>
>>> username =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>> password =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='password']")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
>>> username.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'username' is not defined
>>> username.send_keys("My Username")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'username' is not defined
>>> password.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'password' is not defined
>>> password.send_keys("My Password")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'password' is not defined
>>> try:
...     element = WebDriverWait(driver, 10).until(
...         EC.element_to_be_clickable((By.XPATH, "//button[@type='submit']"))
...     )
... finally:
...     element.click()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
NameError: name 'driver' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
NameError: name 'element' is not defined
>>> if len(driver.find_elements_by_xpath("//form[@id='slfErrorAlert']"))>0:
...     # Element is present
...     print("Not!")
... else:
...     # Element is not present
...     print ("Logged IN!")
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
来自selenium导入webdriver的
>
>>>从selenium.webdriver.common.keys导入密钥
>>>从selenium.webdriver.common.by导入
>>>从selenium.webdriver.support.ui导入WebDriverWait
>>>从selenium.webdriver.support将预期的_条件导入为EC
>>>
>>>driver=webdriver.Firefox()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site packages\selenium\webdriver\firefox\webdriver.py”,第170行,在\uuu init中__
RemoteWebDriver.\uuu init__(
文件“C:\Users\Parsa\AppData\Local\Programs\Python\Python38-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第157行,在\uuu init中__
启动会话(功能、浏览器配置文件)
文件“C:\Users\Parsa\AppData\Local\Programs\Python38-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第252行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“C:\Users\Parsa\AppData\Local\Programs\Python38-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第321行,在execute中
self.error\u handler.check\u响应(响应)
文件“C:\Users\Parsa\AppData\Local\Programs\Python38-32\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.SessionNotCreatedException:消息:找不到匹配的功能集
>>>驱动程序。获取(“https://www.instagram.com/accounts/login/")
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“驱动程序”
>>>
>>>username=WebDriverWait(driver,10).until(EC.element可点击((By.XPATH,“//input[@name='username']))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“驱动程序”
>>>password=WebDriverWait(driver,10).until(EC.element可点击((By.XPATH,“//input[@name='password']))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“驱动程序”
>>>username.clear()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
名称错误:未定义名称“username”
>>>用户名。发送密钥(“我的用户名”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
名称错误:未定义名称“username”
>>>密码。清除()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
名称错误:未定义名称“密码”
>>>密码。发送密钥(“我的密码”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
名称错误:未定义名称“密码”
>>>尝试:
…元素=WebDriverWait(驱动程序,10)。直到(
…EC.element可点击((By.XPATH,//button[@type='submit']))
...     )
…最后:
…元素。单击()
...
回溯(最近一次呼叫最后一次):
文件“”,第2行,在
NameError:未定义名称“驱动程序”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“”,第6行,在
NameError:未定义名称“元素”
>>>如果len(driver.find_elements_by_xpath(“//form[@id='slferralert']”)大于0:
…#元素存在
…打印(“不是!”)
……其他:
…#元素不存在
…打印(“已登录!”)
...
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“驱动程序”

如果您有任何响应,我们将不胜感激。

您必须在系统上安装,才能运行二进制文件。

不要使用系统浏览器数据,请下载任何
。因此
文件将其用作驱动程序。否则,系统更新时总会出错。我尝试在类似的应用程序中使用firefox,但没有成功。我使用了chrome驱动程序相反。
从selenium导入webdriver
driver=webdriver.Chrome(“./chromedriver”,Chrome\u options=Chrome\u options)
您有什么版本的Firefox和Geckodriver?