验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

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

阅读:1115 来源:乙速云 作者:代码code

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日志请求报错如何解决

分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>