iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >解决selenium模块利用performance获取network日志请求报错的问题(亲测有效)
  • 204
分享到

解决selenium模块利用performance获取network日志请求报错的问题(亲测有效)

Python 官方文档:入门教程 => 点击学习

摘要

目录报错翻译报错原因解决方法已解决selenium模块利用perfORMance获取network日志请求,抛出异常selenium.common.exceptions.Invali

已解决selenium模块利用perfORMance获取network日志请求,抛出异常selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: log type ‘performance’ not found

报错问题

一个小伙伴遇到问题跑来私信我,想用selenium模块利用performance获取network日志请求,但是发生了报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴),报错代码如下所示:

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.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内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: 解决selenium模块利用performance获取network日志请求报错的问题(亲测有效)

本文链接: https://www.lsjlt.com/news/200232.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作