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)
相关推荐
威联通网络存储35 分钟前
告别掉帧与素材损毁:威联通 QuTS hero 如何重塑影视后期协同工作流
前端·网络·人工智能·python
Dxy123931021642 分钟前
Python 根据列表中某字段排序:从基础到进阶
开发语言·windows·python
splage1 小时前
Java进阶——IO 流
java·开发语言·python
cliffordl1 小时前
设计模式(python)
python·设计模式
always_TT1 小时前
从Python_Java转学C语言需要注意什么?
java·c语言·python
2301_793804692 小时前
定时任务专家:Python Schedule库使用指南
jvm·数据库·python
穿越世纪的风尘3 小时前
【问题解决】No module named ‘_sqlite3‘
python·centos
qq_416018723 小时前
用Python批量处理Excel和CSV文件
jvm·数据库·python
蓝天守卫者联盟13 小时前
2026乙酸乙酯回收设备厂家选型与技术实践
java·jvm·python·算法
在屏幕前出油4 小时前
06. FastAPI——中间件
后端·python·中间件·pycharm·fastapi