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)
相关推荐
戴西软件12 小时前
戴西 DLM 许可授权管理系统:破解无网络环境下工业软件授权难题,助力制造企业降本增效
网络·人工智能·python·深度学习·程序人生·算法·制造
Dxy123931021612 小时前
Python线程锁:为什么多线程会“打架“,以及怎么解决
开发语言·前端·python
小白学大数据12 小时前
线上故障急救:依托 OpenClaw 日志排查 403 和 503 问题
爬虫·python·selenium·数据分析
databook13 小时前
用SymPy自动因式分解:从面积拼图到代数恒等式
python·数学·动效
艳阳天_.13 小时前
星瀚弹框页面实现
java·前端·python
kernelcraft13 小时前
Boto3:Python 操作 AWS 的官方 SDK
开发语言·python·其他·aws
D3bugRealm13 小时前
cryptography:Python 开发者的加密标准库
开发语言·python·其他
HappyAcmen14 小时前
5.通义向量模型调用
python
python-码博士14 小时前
PyTorch 从零实现 Flow Matching:训练、采样、画图一条龙
人工智能·pytorch·python
王小王-12315 小时前
基于Python的车联网数据聚合与可视化分析平台设计与实现
python·车联网·新能源汽车·车联网聚合分析