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

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

bash 复制代码
chrome.exe --remote-debugging-port=9222

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

python 复制代码
from selenium.webdriver.chrome.service import Service
from seleniumwire import webdriver

chrome_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的话,进行针对性的写法即可

python 复制代码
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 = bearer
                print("获取到登录令牌:" + bearer)
相关推荐
我的xiaodoujiao2 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 41--自定义定制化展示 Allure 测试报告内容
python·学习·测试工具·pytest
2501_942191773 分钟前
YOLO11-Seg-SwinTransformer榛子缺陷识别实战
python
闻道且行之15 分钟前
基于 LLM 的 MCP 架构实战:服务端搭建、工具开发与 Dify 集成全流程
python·架构·nlp·dify·mcp
老蒋每日coding35 分钟前
Python:数字时代的“万能钥匙”
开发语言·python
甄心爱学习1 小时前
KMP算法(小白理解)
开发语言·python·算法
培培说证1 小时前
2026 高职计算机专业考证选择哪个更实用?
python
ASD123asfadxv1 小时前
LCD屏幕表面缺陷检测系统凹陷识别与定位技术分析
python
Ulyanov1 小时前
大规模战场数据与推演:性能优化与多视图布局实战
开发语言·python·性能优化·tkinter·pyvista·gui开发
tjjucheng2 小时前
小程序定制开发哪家口碑好
python
tjjucheng2 小时前
小程序定制开发源头厂家
python