selenium模块利用performance获取network日志请求报错如何解决

发布时间:2023-03-16 11:31:37 作者:iii
来源:亿速云 阅读:201

本篇内容主要讲解“selenium模块利用performance获取network日志请求报错如何解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“selenium模块利用performance获取network日志请求报错如何解决”吧!

报错问题

报错代码如下所示:

chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument("--disable-blink-features=AutomationControlled")
# chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_experimental_option('w3c', True)
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps, options=chrome_options)  #
driver.implicitly_wait(8)
driver.maximize_window()
driver.get(goods_url)  #
# 获取network请求
logs = [json.loads(log['message'])['message'] for log in driver.get_log('performance')]
for log in logs:
	print(log)
	print('------------')

报错信息截图如下所示

selenium模块利用performance获取network日志请求报错如何解决

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: log type 'performance' not found

报错翻译

报错信息内容翻译如下所示

selenium.mon.解释.无效参数异常:消息:无效参数:找不到日志类型“performance”

报错原因

报错原因如下

使用caps['loggingPrefs'] = {'performance': 'ALL'}监控network请求日志记录,但是新版selenium模块,改名了所以会提示找不到performance

小伙伴们按下面的方法修改代码即可解决!!!

解决方法

新版selenium模块将caps['loggingPrefs'] = {'performance': 'ALL'}修改为下方代码即可:

caps["goog:loggingPrefs"] = {"performance": "ALL"}

再次运行代码成功了:

selenium模块利用performance获取network日志请求报错如何解决

到此,相信大家对“selenium模块利用performance获取network日志请求报错如何解决”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. Python+selenium+firefox如何模拟登录微博并爬取数据
  2. Python爬虫中Selenium的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

selenium network performance

上一篇:Spring集成Mybatis怎么实现

下一篇:linux sleep能不能线程延时

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》