TypeError: WebDriver.init() got an unexpected keyword argument 'desired_capabilities'
新版本不支持desired_capabilities的问题解决
不同版本有不同的配置方法
历史版本设置方法,selenium==4.1.0
from selenium import webdriver
options = webdriver.ChromeOptions()
path = Service(r'C:\\chromedriver.exe')
caps = {"browserName": "chrome", 'goog:loggingPrefs': {'performance': 'ALL'}} # 开启日志性能监听
driver = webdriver.Chrome(service=path, chrome_options=options,desired_capabilities=caps)
performance_log = driver.get_log('performance') # 获取名称为 performance 的日志
for i in range(len(performance_log)):
message = json.loads(performance_log[i]['message'])
message = message['message']['params']
request = message.get('request')
if(request is None):
continue
url = request.get('url')
if(url == "https://xx.com"):
# 通过requestId获取接口内容
detail_response = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': message['requestId']})
return detail_response
selenium == 4.14.0 就不支持上述设置方法
from selenium import webdriver
options = webdriver.ChromeOptions()
path = Service(r'C:\\chromedriver.exe')
options.set_capability('goog:loggingPrefs', {'performance': 'ALL'}) # 开启日志性能监听
driver = webdriver.Chrome(service=path, options=options)
performance_log = driver.get_log('performance') # 获取名称为 performance 的日志
for i in range(len(performance_log)):
message = json.loads(performance_log[i]['message'])
message = message['message']['params']
request = message.get('request')
if(request is None):
continue
url = request.get('url')
if(url == "https://xx.com"):
# 通过requestId获取接口内容
detail_response = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': message['requestId']})
return detail_response
版权归原作者 u014376732 所有, 如有侵权,请联系我们删除。