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)
相关推荐
dagouaofei几秒前
AI生成个性化年终总结PPT
人工智能·python·powerpoint
white-persist1 小时前
VSCode 快捷键大全:从设计理念到场景化高效运用(详细解析)(文章末尾有vim快捷键大全)
linux·ide·vscode·python·编辑器·系统安全·vim
liliangcsdn1 小时前
python threading异步并发调用示例
python
计算机毕设匠心工作室1 小时前
【python大数据毕设实战】全面皮肤病症状数据可视化分析系统、Hadoop、计算机毕业设计、包括数据爬取、数据分析、数据可视化、机器学习、实战教学
后端·python·mysql
码界奇点2 小时前
基于Python与Pygame的多功能游戏系统设计与实现
python·游戏·毕业设计·pygame·源代码管理
万邦科技Lafite2 小时前
一键获取淘宝店铺所有商品信息,实时监控商品数据
开发语言·数据库·python·api·开放api·电商开放平台·淘宝开放平台
小糖学代码2 小时前
LLM系列:1.python入门:2.数值型对象
人工智能·python·ai
零日失眠者3 小时前
这5个Python库一旦掌握就离不开
后端·python
用户8356290780513 小时前
如何使用 Python 从 Word 文档中批量提取表格数据
后端·python
Jerryhut3 小时前
sklearn函数总结四——归一化和标准化
人工智能·python·机器学习·jupyter·sklearn