溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

selenium模塊利用performance獲取network日志請求報錯如何解決

發(fā)布時間:2023-03-16 11:31:37 來源:億速云 閱讀:243 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“selenium模塊利用performance獲取network日志請求報錯如何解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“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

報錯翻譯

報錯信息內(nèi)容翻譯如下所示

selenium.mon.解釋.無效參數(shù)異常:消息:無效參數(shù):找不到日志類型“performance”

報錯原因

報錯原因如下

使用caps['loggingPrefs'] = {'performance': 'ALL'}監(jiān)控network請求日志記錄,但是新版selenium模塊,改名了所以會提示找不到performance。

小伙伴們按下面的方法修改代碼即可解決!??!

解決方法

新版selenium模塊將caps['loggingPrefs'] = {'performance': 'ALL'}修改為下方代碼即可:

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

再次運行代碼成功了:

selenium模塊利用performance獲取network日志請求報錯如何解決

到此,相信大家對“selenium模塊利用performance獲取network日志請求報錯如何解決”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI