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)
相关推荐
柠檬叶子C4 分钟前
【Python】解决 No module named ‘imp‘ 问题 | Python3 中废弃的 imp 模块
开发语言·python
我想吃烤肉肉6 分钟前
wait_until=“domcontentloaded“ 解释
开发语言·前端·javascript·爬虫·python
weixin199701080169 分钟前
废旧物资 item_search - 按关键字搜索商品列表接口对接全攻略:从入门到精通
数据库·python
海棠AI实验室9 分钟前
第二章 从脚本到工程:进阶学习的 5 个方法论(可维护性/可复现/可评估/可扩展/可交付)
python·数据
学习3人组18 分钟前
CentOS 系统下 ModelScope 模型下载的默认目录
linux·python·centos
song1502653729822 分钟前
空间站太阳能帆板电池 组件性能测试 AM0太阳光模拟器
开发语言·python
星火开发设计29 分钟前
Python数列表完全指南:从基础到实战
开发语言·python·学习·list·编程·知识·期末考试
星浩AI34 分钟前
LCEL:打造可观测、可扩展、可部署的 LangChain 应用
人工智能·后端·python
这儿有一堆花38 分钟前
Python 虚拟环境的配置与管理指南
开发语言·python
Generalzy43 分钟前
深度觉醒 — Deep Agents(三座大山 — Agent 的核心挑战)
python