问题:
报错:selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found

解决方法
查看导包是否正确:
如果是webdriver.Chrome,那么导包的一切都要是chrome的
如果是webdriver.Firefox,那么导入的包也都源于firefox的包
出现这个问题是因为由于selenium很多类都很相似,如selenium.webdriver.firefox.options与selenium.webdriver.chrome.options,导致导包的时候容易出错,而代码本身是没有问题的。
问题解析
错误代码如下:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options #此处导入的是firefox
url = 'https://www.baidu.com'
options = Options()
options.add_argument('--headless')
browser = webdriver.Chrome(options=options) #调用的是Chrome
browser.get(url=url)
print(browser.page_source[:300])
browser.close()
没有检索到标题

本文讲述了在使用Selenium时遇到的SessionNotCreatedException错误,主要原因是导入Firefox和Chrome的选项类时混淆。作者提供了检查导包和修正代码的建议,确保正确选择对应浏览器的选项类。
6万+

被折叠的 条评论
为什么被折叠?



