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)
相关推荐
人工智能AI技术1 小时前
【Agent从入门到实践】21 Prompt工程基础:为Agent设计“思考指令”,简单有效即可
人工智能·python
2501_941322031 小时前
铆钉表面缺陷检测:YOLO13-BiFPN模型实现与性能优化_1
python
CCPC不拿奖不改名2 小时前
python基础面试编程题汇总+个人练习(入门+结构+函数+面向对象编程)--需要自取
开发语言·人工智能·python·学习·自然语言处理·面试·职场和发展
我送炭你添花2 小时前
Pelco KBD300A 模拟器:10.报警联动规则编辑与执行
python·自动化·运维开发
眼眸流转2 小时前
MCP学习笔记
python·uv·pydantic·mcp
千禧皓月2 小时前
huggingface-cli下载数据集和模型
python
DREAM依旧2 小时前
本地微调的Ollama模型部署到Dify平台上
人工智能·python
小陈phd2 小时前
langGraph从入门到精通(九)——基于LangGraph构建具备多工具调用与自动化摘要能力的智能 Agent
人工智能·python·langchain
一晌小贪欢2 小时前
Python 对象的“Excel 之旅”:使用 openpyxl 高效读写与封装实战
开发语言·python·excel·表格·openpyxl·python办公·读取表格
【赫兹威客】浩哥2 小时前
【赫兹威客】Python解释器部署教程
python