我试图使用Selenium Webdriver打开firefox浏览器。在进行网络抓取和抓取项目时,/usr/local/bin
中已经有我的geckodriver。
还尝试了版本为17.0、19.0、23.0的geckodriver;找到组合。
我尝试过的是以下代码。
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
driver=webdriver.Firefox()
driver.get("https://kissanime.ru/")
driver.maximize_window()
在执行代码时,它弹出一个错误:
Traceback (most recent call last):
File "downloader.py", line 9, in <module>
driver=webdriver.Firefox()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-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
答案 0 :(得分:0)
此错误消息...
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
...表示 GeckoDriver 无法启动/产生新的 WebBrowsing会话,即 Firefox浏览器会话。
您的主要问题可能是所使用的二进制版本之间的不兼容性,如下所示:
在启动WebDriver / WebBrowser会话时,将参数 executable_path 连同 GeckoDriver 的绝对路径一起传递:
Windows操作系统格式:
driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
Linux 和 MAC OS X 格式:
driver = webdriver.Firefox(executable_path='/path/to/geckodriver')
以非root用户身份执行Test
。
driver.quit()
方法内调用tearDown(){}
,以优雅地关闭和销毁 WebDriver 和 Web Client 实例。