惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
V
V2EX
Vercel News
Vercel News
U
Unit 42
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
J
Java Code Geeks
WordPress大学
WordPress大学
罗磊的独立博客
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG

博客园 - 隐客

商品期权的保证金计算 写个chrome插件屏蔽某些视频,防止孩子看些不正常的视频 获取个股信息的东财数据 AI量化qlib学习笔记四:测试模型 AI量化qlib学习笔记三:训练模型 AI量化qlib学习笔记二:转换数据 AI量化qlib学习笔记 一:清洗数据 python 打包工具 python: 与通达信联动 随手写了街机一键发招的代码 使用pybind11封装c++的dll,供python调用 用py-spy对python线程查看cpu等资源 占用和消耗 Windows Server 2012无法安装 .NET3.5-安装角色或功能失败,找不到源文件 vscode 扩展商店打不开的解决办法 通过1分钟生成其它线的bar配置文件 用numpy读取结构化二进制文件 微信pc防撤回修改笔记 关于在python中时间的转换 把本地vscode项目代码传到gitee上
通过selenium获取性能日志中的response的body
隐客 · 2024-03-24 · via 博客园 - 隐客

selenium == 4.14.0 以下的就不支持以下设置方法 参见:详见

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time
import json
# 设置 Chrome WebDriver 的路径
chrome_driver_path = r"E:\work\selenium\chromedriver.exe"  # 请替换成你的 Chrome 驱动程序的路径
 
 
options = webdriver.ChromeOptions()
path = Service(chrome_driver_path)
options.set_capability('goog:loggingPrefs', {'performance': 'ALL'}) # 开启日志性能监听
driver = webdriver.Chrome(service=path, options=options)
driver.get("https://www.baidu.com")
time.sleep(3)
performance_log = driver.get_log('performance')  # 获取名称为 performance 的日志
for i in range(len(performance_log)):
    message = json.loads(performance_log[i]['message'])
    message = message['message']['params']
    request = message.get('request')
    if(request is None):
        continue

    url = request.get('url')
    if(url == "https://www.baidu.com/"):
        # 通过requestId获取接口内容
        detail_response = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': message['requestId']})
    else:
        print("not:",url)
print( detail_response)