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

推荐订阅源

WordPress大学
WordPress大学
M
MIT News - Artificial intelligence
MyScale Blog
MyScale Blog
博客园_首页
G
Google Developers Blog
博客园 - 【当耐特】
美团技术团队
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
小众软件
小众软件
博客园 - 司徒正美
雷峰网
雷峰网
T
Tailwind CSS Blog
V
V2EX
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
罗磊的独立博客
量子位
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - 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)