Python+selenium解决报错:SessionNotCreatedException session not created: No matching capabilities found

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

Python+selenium解决报错:SessionNotCreatedException session not created: No matching capabilities found_第1张图片

解决方法
查看导包是否正确:

如果是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,爬虫,Python,python,selenium,开发语言,爬虫,网络爬虫)