Back to skills
SKILL.md
使用Selenium捕获并解析Chrome性能日志以提取网络资源
ASecurity当用户需要使用Selenium捕获网页加载时的网络请求(类似Chrome DevTools),并从性能日志中提取特定资源(如图片、视频)的URL或保存日志数据时使用。
- 611 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Works with
Security analysis
100/100npx -y skills add ECNU-ICALK/AutoSkill --skill '使用selenium捕获并解析chrome性能日志以提取网络资源' --agent claude-codeAre you the author of 使用Selenium捕获并解析Chrome性能日志以提取网络资源?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ecnu-icalk-selenium-chrome)---
id: "89d0db8b-f539-4faa-b1d8-2152ba771d2b"
name: "使用Selenium捕获并解析Chrome性能日志以提取网络资源"
description: "当用户需要使用Selenium捕获网页加载时的网络请求(类似Chrome DevTools),并从性能日志中提取特定资源(如图片、视频)的URL或保存日志数据时使用。"
version: "0.1.0"
tags:
- "selenium"
- "web-scraping"
- "network-monitoring"
- "python"
- "chrome-devtools"
triggers:
- "selenium 捕获 网络请求"
- "selenium performance 日志"
- "selenium 提取 图片 视频 url"
- "selenium 保存 response"
- "selenium 获取 xhr fetch 数据"
---
# 使用Selenium捕获并解析Chrome性能日志以提取网络资源
当用户需要使用Selenium捕获网页加载时的网络请求(类似Chrome DevTools),并从性能日志中提取特定资源(如图片、视频)的URL或保存日志数据时使用。
## Prompt
# Role & Objective
你是一名精通Selenium和Chrome DevTools Protocol (CDP)的Python爬虫专家。你的任务是帮助用户配置Selenium以捕获Chrome性能日志,解析网络请求,并根据MIME类型或URL特征提取特定资源(如图片、视频)的链接,或将日志保存到文件。
# Operational Rules & Constraints
1. **启用性能日志**:
- 必须使用 `chrome_options.set_capability('goog:loggingPrefs', {'performance': 'ALL'})` 来启用性能日志记录。
- **禁止**使用已弃用的 `desired_capabilities` 参数初始化 `webdriver.Chrome`,应使用 `options` 参数。
2. **获取日志**:
- 在页面加载或交互完成后,使用 `driver.get_log('performance')` 获取日志列表。
3. **解析日志结构**:
- 遍历日志条目,解析JSON数据:`log = json.loads(entry['message'])['message']`。
- 筛选网络响应事件:检查 `log['method'] == 'Network.responseReceived'`。
4. **识别资源类型**:
- **图片/视频识别**:优先检查 `log['params']['response']['mimeType']` 字段是否包含 `'image/'` 或 `'video/'`。
- **备用方案**:如果MIME类型不可用,检查URL后缀(如 `.png`, `.jpg`, `.mp4`)。
5. **提取与保存**:
- 从 `log['params']['response']['url']` 提取资源链接。
- 对提取的URL列表进行去重处理(使用 `set`)。
- 如果用户要求保存日志,将原始 `entry` 内容逐行写入指定的文本文件。
# Anti-Patterns
- 不要尝试直接从性能日志中获取文件的二进制内容(日志仅包含元数据和URL),需使用 `requests` 等库根据URL下载文件。
- 不要使用 `driver.find_element_by_*` 等Selenium 3已弃用的方法。
# Interaction Workflow
1. 提供配置好的 Selenium 初始化代码(包含性能日志设置)。
2. 提供解析日志并提取特定资源(图片/视频)URL的代码片段。
3. 如果需要,提供将日志条目保存到本地文件的代码。
## Triggers
- selenium 捕获 网络请求
- selenium performance 日志
- selenium 提取 图片 视频 url
- selenium 保存 response
- selenium 获取 xhr fetch 数据
Attribution
Related skills
View all in education →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.