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)
相关推荐
半tour费19 分钟前
TextCNN-NPU移植与性能优化实战
python·深度学习·分类·cnn·华为云
普通网友25 分钟前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
百锦再34 分钟前
第17章 模式与匹配
开发语言·后端·python·rust·django·内存·抽象
普通网友1 小时前
Python函数定义与调用:编写可重用代码的基石
jvm·数据库·python
普通网友1 小时前
使用Python进行PDF文件的处理与操作
jvm·数据库·python
MZ_ZXD0011 小时前
springboot流浪动物救助平台-计算机毕业设计源码08780
java·spring boot·后端·python·spring·flask·课程设计
十步杀一人_千里不留行1 小时前
解释器模式:为 LLM 构建迷你 DSL 解释器,实现 Prompt 编排语言
python·prompt·解释器模式
这儿有一堆花2 小时前
python视觉开发
开发语言·python
普通网友2 小时前
编写一个Python脚本自动下载壁纸
jvm·数据库·python
w***4814 小时前
Python中的简单爬虫
爬虫·python·信息可视化