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

作者:袁袁袁袁满 时间:2022-12-22 11:09:26 

已解决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模块利用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日志请求报错的问题(亲测有效)

以上是此问题报错原因的解决方法,欢迎评论区留言讨论是否能解决,博主看到会给出回复和你所遇到的报错问题解决方法!!!

来源:https://blog.csdn.net/yuan2019035055/article/details/129437741

标签:selenium,network,日志请求,异常
0
投稿

猜你喜欢

  • asp的日期转换星座函数

    2010-06-09 21:05:00
  • asp + oracle 分页方法

    2010-05-11 20:09:00
  • Go Struct结构体的具体实现

    2023-09-02 04:54:01
  • Python 读取千万级数据自动写入 MySQL 数据库

    2023-11-08 09:25:47
  • 描述性列表的表现形式

    2008-09-17 13:43:00
  • 巧用Dreamweaver MX设计导航栏特效

    2009-07-10 13:17:00
  • PHP set_time_limit(0)长连接的实现分析

    2023-11-06 11:46:20
  • Go 值传递与引用传递的方法

    2023-06-25 03:11:11
  • ipython jupyter notebook中显示图像和数学公式实例

    2022-06-20 12:19:37
  • 编写安全的SQL Server扩展存储过程

    2008-11-25 11:16:00
  • 一些文档中没有介绍的SQL Server DBCC命令

    2008-12-09 14:24:00
  • Python字符串中添加、插入特定字符的方法

    2021-05-14 00:16:53
  • JS onmousemove鼠标移动坐标接龙DIV效果实例

    2023-08-08 19:59:13
  • 关于pyinstaller生成.exe程序报错:缺少.ini文件的分析

    2023-12-25 13:43:22
  • Django学习笔记之ORM基础教程

    2022-07-25 22:59:07
  • PHP使用laravel邮件服务发送邮件

    2023-05-25 03:48:23
  • python中的集合及集合常用的使用方法

    2023-05-04 11:14:11
  • 简单介绍Python的Django框架加载模版的方式

    2022-09-17 16:49:31
  • MySQL中SQL的单字节注入与宽字节注入

    2009-03-25 14:49:00
  • python处理文本文件实现生成指定格式文件的方法

    2022-01-07 21:41:43
  • asp之家 网络编程 m.aspxhome.com