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)
相关推荐
xixixi7777717 分钟前
拥抱AI大模型时代:开发者如何利用智能编程工具提升效率
人工智能·python·ai·大模型·aigc·代码
李昊哲小课18 分钟前
Python 高级数据结构
开发语言·数据结构·python
小蜗牛~向前冲27 分钟前
大模型学习系列-Embedding与向量数据库
人工智能·python·神经网络·学习·机器学习·embedding
MediaTea27 分钟前
Python:词频统计流程及综合示例
开发语言·python
鲜于言悠9051 小时前
博客系统测试报告
python·功能测试·selenium·jmeter·测试用例·集成测试·pytest
全栈凯哥1 小时前
13.Python中while循环完全指南
python
所谓伊人,在水一方3331 小时前
【Python数据可视化精通】第9讲 | 实时数据流可视化
开发语言·python·信息可视化·数据分析·pandas
困死,根本不会1 小时前
Python 基础语法速通:从入门到上手
windows·笔记·python·学习
无风听海1 小时前
深入解析 Python dotenv
网络·python·rpc
在屏幕前出油1 小时前
02. FastAPI——路由
服务器·前端·后端·python·pycharm·fastapi