欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > Python使用seleniumwire接管Chrome查看控制台中参数

Python使用seleniumwire接管Chrome查看控制台中参数

2025/2/5 11:53:25 来源:https://blog.csdn.net/qq_57600840/article/details/145200183  浏览:    关键词:Python使用seleniumwire接管Chrome查看控制台中参数

1、cmd打开控制台,启动谷歌并制定端口号,找不到文件的加环境变量

chrome.exe --remote-debugging-port=9222

2、获取F12控制台中接口参数

from selenium.webdriver.chrome.service import Service
from seleniumwire import webdriverchrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_options.set_capability("browserName", 'chrome')
chrome_options.set_capability("goog:chromeOptions", {'perfLoggingPrefs': {'enableNetwork': True}, 'w3c': False})
chrome_options.set_capability("goog:loggingPrefs", {"performance": "ALL"})
service = Service(executable_path='D:\crack-plugin\chromedriver-win64\chromedriver.exe')
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get("https://example.com")
print("已监听到网页,名称为:" + driver.title)
performance_log = driver.get_log('performance')
authorization = None
print(authorization)

3、如果需要获取针对性的参数,比如header中的登录令牌Bearer Token的话,进行针对性的写法即可

for log in performance_log:if "Authorization" in log['message']:message = json.loads(log['message'])if "Network.requestWillBeSentExtraInfo" == message['message']['method']:bearer = message['message']['params']['headers']['Authorization']authorization = bearerprint("获取到登录令牌:" + bearer)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com