解決selenium模塊利用performance獲取network日志請求報錯的問題(親測有效)
已解決selenium模塊利用performance獲取network日志請求,拋出異常selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: log type ‘performance’ not found
報錯問題
一個小伙伴遇到問題跑來私信我,想用selenium模塊利用performance獲取network日志請求,但是發(fā)生了報錯(當時他心里瞬間涼了一大截,跑來找我求助,然后順利幫助他解決了,順便記錄一下希望可以幫助到更多遇到這個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
報錯翻譯
報錯信息內(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"}
再次運行代碼成功了:
以上是此問題報錯原因的解決方法,歡迎評論區(qū)留言討論是否能解決,博主看到會給出回復(fù)和你所遇到的報錯問題解決方法?。?!
到此這篇關(guān)于解決selenium模塊利用performance獲取network日志請求報錯的問題(親測有效)的文章就介紹到這了,更多相關(guān)selenium內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python單個項目列表轉(zhuǎn)換為整數(shù)的實現(xiàn)
本文主要介紹了Python單個項目列表轉(zhuǎn)換為整數(shù)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-02-02詳談python中subprocess shell=False與shell=True的區(qū)別
這篇文章主要介紹了詳談python中subprocess shell=False與shell=True的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04Python中os.system()、subprocess.run()、call()、check_output()的使用
這篇文章主要介紹了Python中os.system()、subprocess.run()、call()、check_output()的使用案例,本文結(jié)合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07Python數(shù)組遍歷的簡單實現(xiàn)方法小結(jié)
這篇文章主要介紹了Python數(shù)組遍歷的簡單實現(xiàn)方法,結(jié)合實例總結(jié)分析了Python針對數(shù)組的元素,索引常用遍歷技巧,需要的朋友可以參考下2016-04-04