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)
相关推荐
hef28822 分钟前
SQL和Python怎么选?数据分析工具实战指南
python·sql·数据分析
徐安安ye22 分钟前
FlashAttention长程依赖建模:局部+全局的Hybrid Spiral结构设计
python·深度学习·机器学习
IT策士43 分钟前
Django 从 0 到 1 打造完整电商平台:商品排序与浏览量统计
后端·python·django
godspeed_lucip1 小时前
LLM和Agent——专题3: Agentic Workflow 入门(4)
人工智能·python
godspeed_lucip1 小时前
LLM和Agent——专题3: Agentic Workflow 入门(2)
网络·人工智能·python
mingshili1 小时前
[Python] Python中自带模块级的单例模式-不需要定义单例类
python·单例模式
alphaTao1 小时前
LeetCode 每日一题 2026/5/18-2026/5/24
python·leetcode
徐安安_ye11 小时前
FlashAttention学习路线:从调API到写算子,你该走哪条路
python·学习
IT策士2 小时前
Django 从 0 到 1 打造完整电商平台:商品搜索
后端·python·django
茉莉玫瑰花茶2 小时前
LangGraph 持久化(Persistence)[ 2 ]
开发语言·python·ai·langgraph