agentsclimarketplace

使用selenium捕获并解析chrome性能日志以提取网络资源

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/使用selenium捕获并解析chrome性能日志以提取网络资源

当用户需要使用Selenium捕获网页加载时的网络请求(类似Chrome DevTools),并从性能日志中提取特定资源(如图片、视频)的URL或保存日志数据时使用。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 使用selenium捕获并解析chrome性能日志以提取网络资源

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.0 KB, 719 tokens by cl100k_base, as published. Nobody here has run it

使用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 数据

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.