练习开发Skill——网页内容抓取Skill(website-content-fetch)

练习开发Skill——网页内容抓取Skill(website-content-fetch)
现在使用AI帮我们找一些资料帮我们分析问题的场景多的数不胜数,但是在AI找资料的过程中,我们对AI抓取的内容是不知道,也不可以明确指定范围的,主要是靠模型本身能力去收集,当然也可以增加提示词,加以控制。

当然目前解决方案也有很多:

  • 增加更详细的提示词,描述更细致,控制更精细,过程更明确
  • 同时也有Tavily Search、SearXNG等搜索智能体,可以更好指定搜索参数,如何处理搜索结果等
  • 引用Skills、MCP等丰富大模型能力

了解到这些的时候,想着练习写一个Skills,实现网页内容抓取(其实很多东西都已经实现了,本文就是学习和分享),也了解一下Skills的开发

Skills的项目结构

skill-name/ ├── SKILL.md (唯一必需) │ ├── YAML 格式 (name, description 必须) │ └── Markdown instructions (介绍使用Markdown) └── Bundled Resources (可选的其他内容,和SKILL.md同级) ├── scripts/ - 存放可执行脚本(例如 Python 等) ├── references/ - 存放文档、API说明、领域知识 ├── examples/ - 存放示例文件 ├── evals/ - 存放测试说明 └── assets/ - 准备模板、图标、样板代码。确保格式正确(PPT、Word、图片等) 

SKILL.md元数据介绍

元数据字段:

字段必填说明
nameSkill 显示名称,默认使用目录名,仅支持小写字母、数字和短横线(最长 64 字符)
description技能用途及使用场景,Claude 根据它判断是否自动应用
argument-hint自动补全时显示的参数提示,如 [issue-number]、[filename] [format]
disable-model-invocation设为 true 禁止 Claude 自动触发,仅能手动 /name 调用(默认 false)
user-invocable设为 false 从 / 菜单隐藏,作为后台增强能力使用(默认 true)
allowed-toolsSkill 激活时 Claude 可无授权使用的工具
modelSkill 激活时使用的模型
context设为 fork 时在子代理上下文中运行
agent子代理类型(配合 context: fork 使用)
hooks技能生命周期钩子配置

scripts

Skills采用Prompt + Scripts架构,Scripts必须绑定特定运行时环境

  • Skills的实现多采用Python脚本,也是大模型运行的主要环境
  • Node.js Skills:需配置node_modules及package.json
  • Bash Scripts:仅需基础Shell环境(但可能依赖系统工具包)

开发案例

Python还不太熟悉,用Node写了一个

主要实现的是:获取网页中所有的文本内容,如果有可以识别的媒体文件,将媒体资源的URL获取下来

整体项目目录结构,skillswebsite-content-fetch是本次的skill主目录,我们可以在一个项目中开发多个skill统一放在skills中,在一起维护也可以随时使用和优化其他skill

请添加图片描述

SKILL.md

--- name: website-content-fetch description: Fetch and extract content from websites. Use this skill whenever the user mentions fetching website content, extracting text from web pages, or needing to get content from a URL, even if they don't explicitly ask for a 'website content fetch' skill. --- 

package.json

{"name":"website-content-fetch","version":"1.0.0","description":"fetching website content","main":"scripts/fetch-content.js","scripts":{"test":"node scripts/fetch-content.js"},"keywords":["openclaw","skill","website","content","fetch"],"author":"","license":"MIT","dependencies":{"axios":"^1.6.2","cheerio":"^1.0.0-rc.12"}}

scripts

fetch-content.js

const axios =require("axios");const cheerio =require("cheerio");const path =require("path");const fs =require("fs");/** * Fetch website content * @param {string} url - The URL to fetch * @param {object} options - Optional parameters * @param {string} options.saveDir - Directory to save media files (optional) * @returns {Promise<object>} - The fetched content and metadata */asyncfunctionfetchWebsiteContent(url, options ={}){try{const response =await axios.get(url);const $ = cheerio.load(response.data);// Extract text contentlet content =$("body").text().trim();// Clean up content content = content.replace(/\s+/g," ");// Extract media resourcesconst media ={images:[],videos:[],audios:[],};// Extract images$("img").each((i, elem)=>{const src =$(elem).attr("src");const alt =$(elem).attr("alt")||"";if(src){const absoluteUrl =newURL(src, url).href; media.images.push({url: absoluteUrl,alt: alt,});}});// Extract videos$("video, iframe").each((i, elem)=>{let src =$(elem).attr("src");if(!src &&$(elem).attr("data-src")){ src =$(elem).attr("data-src");}if(src){const absoluteUrl =newURL(src, url).href; media.videos.push({url: absoluteUrl,});}});// Extract audios$("audio").each((i, elem)=>{const src =$(elem).attr("src");if(src){const absoluteUrl =newURL(src, url).href; media.audios.push({url: absoluteUrl,});}});// Save media files if saveDir is providedif(options.saveDir){// Create save directory if it doesn't existif(!fs.existsSync(options.saveDir)){ fs.mkdirSync(options.saveDir,{recursive:true});}// Save imagesfor(let i =0; i < media.images.length; i++){const image = media.images[i];try{const imageResponse =await axios.get(image.url,{responseType:"stream",});const imageName =`image_${i}_${path.basename(newURL(image.url).pathname)}`;const imagePath = path.join(options.saveDir, imageName);const writer = fs.createWriteStream(imagePath); imageResponse.data.pipe(writer);awaitnewPromise((resolve, reject)=>{ writer.on("finish",()=>resolve()); writer.on("error", reject);}); image.localPath = imagePath;}catch(error){ console.error(`Error saving image ${image.url}:`, error.message);}}// Save videosfor(let i =0; i < media.videos.length; i++){const video = media.videos[i];try{const videoResponse =await axios.get(video.url,{responseType:"stream",});const videoName =`video_${i}_${path.basename(newURL(video.url).pathname)}`;const videoPath = path.join(options.saveDir, videoName);const writer = fs.createWriteStream(videoPath); videoResponse.data.pipe(writer);awaitnewPromise((resolve, reject)=>{ writer.on("finish",()=>resolve()); writer.on("error", reject);}); video.localPath = videoPath;}catch(error){ console.error(`Error saving video ${video.url}:`, error.message);}}// Save audiosfor(let i =0; i < media.audios.length; i++){const audio = media.audios[i];try{const audioResponse =await axios.get(audio.url,{responseType:"stream",});const audioName =`audio_${i}_${path.basename(newURL(audio.url).pathname)}`;const audioPath = path.join(options.saveDir, audioName);const writer = fs.createWriteStream(audioPath); audioResponse.data.pipe(writer);awaitnewPromise((resolve, reject)=>{ writer.on("finish",()=>resolve()); writer.on("error", reject);}); audio.localPath = audioPath;}catch(error){ console.error(`Error saving audio ${audio.url}:`, error.message);}}}return{ content,length: content.length, url, media,};}catch(error){ console.error("Error fetching website content:", error);thrownewError(`Failed to fetch content from ${url}: ${error.message}`);}}// If run directly, test the functionif(require.main === module){const url = process.argv[2]||"https://example.com";const saveDir = process.argv[3];const options ={};if(saveDir){ options.saveDir = saveDir;}fetchWebsiteContent(url, options).then((result)=>{ console.log("Fetched content:"); console.log(`URL: ${result.url}`); console.log(`Length: ${result.length} characters`); console.log("Content:"); console.log(result.content);// Display media resources console.log("\nMedia resources:");if(result.media.images.length >0){ console.log("Images:"); result.media.images.forEach((image, index)=>{ console.log(`${index +1}. ${image.url} (alt: ${image.alt})`);if(image.localPath){ console.log(` Saved to: ${image.localPath}`);}});}if(result.media.videos.length >0){ console.log("\nVideos:"); result.media.videos.forEach((video, index)=>{ console.log(`${index +1}. ${video.url}`);if(video.localPath){ console.log(` Saved to: ${video.localPath}`);}});}if(result.media.audios.length >0){ console.log("\nAudios:"); result.media.audios.forEach((audio, index)=>{ console.log(`${index +1}. ${audio.url}`);if(audio.localPath){ console.log(` Saved to: ${audio.localPath}`);}});}}).catch((error)=>{ console.error("Error:", error.message);});} module.exports ={ fetchWebsiteContent };

evals

evals.json

{"skill_name":"website-content-fetch","evals":[{"id":1,"prompt":"Fetch content from https://example.com","expected_output":"Should return the text content of example.com","files":[]},{"id":2,"prompt":"Fetch content from a nonexistent domain","expected_output":"Should throw an error about failed to fetch content","files":[]},{"id":3,"prompt":"Fetch content without providing a URL","expected_output":"Should throw an error about URL being required","files":[]}]}

测试

将开发的skill目录website-content-fetch引入支持skill的AI助手或者开发IDE,此处不赘述,只要website-content-fetch放入对应的skills目录,助手或者IDE都可以识别到。

开发的时候,只需要在项目中,和AI工具说使用website-content-fetch skill为我抓取https://www.baidu.com中的内容即可,比如我使用Trae对话,AI会自动发现该工具,并识别scripts的语言识别到node环境会开始install依赖,再用skill执行任务

请添加图片描述


install成功之后,环境准备就绪,就会按照skill开发的功能执行任务了

请添加图片描述
  • 最后再反复测试结果,调试scripts功能,优化逻辑
  • 丰富SKILL内容,为AI下次识别工具,对skill的功能和逻辑有更好的理解,更精确的执行任务

最后附上Github地址
aubrey-skills

Read more

2026国家自然基金ai声明在哪里写?

2026国家自然基金ai声明在哪里写? 下面图中 根据2026年国家自然科学基金(NSFC)最新要求,‌AI使用声明需在申请书中明确撰写并提交‌,具体位置和撰写方式如下: 声明撰写位置建议 * ‌推荐位置‌:将AI使用声明作为独立小节,置于“‌研究方案‌”或“‌研究基础‌”部分之后,也可放在“‌伦理合规与科研诚信‌”相关章节中。 * ‌标题建议‌:使用如“‌3.X 人工智能工具使用边界与研究诚信保障策略‌”等清晰标题,便于评审查阅‌4。 声明撰写原则(权威指引) 根据基金委最新导向及多位专家解读,声明应遵循以下原则: * ‌诚实透明,宜粗不宜细‌:无需逐段罗列AI在立项依据、技术路线等各部分的具体使用情况‌610。 ‌整体性说明即可‌:例如: “本项目申请书的撰写过程中,申请人使用[工具名称,

【深度解析 Anthropic Claude-Code 2.1.88 源码结构:从 Source Map 揭秘 AI 编程助手内部实现】

前言 近日,一个开源项目在 GitHub 上引起了广泛关注。这个名为 claude-code-sourcemap 的项目通过技术手段还原了 Anthropic 官方 Claude-Code 工具 2.1.88 版本的源代码。作为技术研究者和 AI 编程工具的爱好者,我深入分析了这个项目,为大家带来详细的源码结构解析。 项目概况 项目名称:claude-code-sourcemap GitHub 地址:https://github.com/xy200303/claude-code-sourcemap 版本:2.1.88(基于 @anthropic-ai/claude-code npm 包) 文件数量:4756 个文件(包含 1884 个 .ts/.tsx 源文件) 还原方式:

AI文字语音项目:搭建一个支持情感控制、可二次封装的TTS服务

AI文字语音项目:搭建一个支持情感控制、可二次封装的TTS服务

文章目录 * 📦 第一阶段:环境准备与模型部署 * 🧱 第二阶段:核心封装与情感控制接口 * 🚀 第三阶段:使用与测试 * 🔧 第四阶段:部署为API服务(Flask示例) * 📝 重要补充与高级扩展 📦 第一阶段:环境准备与模型部署 1. 创建项目并安装核心依赖 打开你的终端,执行以下命令: # 1. 创建项目目录mkdir MyEmotionalTTS &&cd MyEmotionalTTS # 2. 创建Python虚拟环境(推荐) python -m venv venv # 在Linux/Mac上激活:source venv/bin/activate # 在Windows上激活:# venv\Scripts\activate# 3. 安装PyTorch (根据你的CUDA版本选择,以CUDA 12.1为例) pip install torch

【保姆级教程】Claude Code 进阶指南:用 Everything Claude Code 打造更有“记忆”的 AI 程序员

【保姆级教程】Claude Code 进阶指南:用 Everything Claude Code 打造更有“记忆”的 AI 程序员

目录 第一部分:环境准备与安装 第二部分:插件化极速部署 第一步:安装“Everything”插件核心 第二步:手动注入“大脑规则”(必做!) 第三步:验证安装 & 初始化包管理器 第三部分:实战演练 1. 提出需求:不要直接写代码,先做计划 2. 见证“降维打击”级的规划能力 3. 架构师的“追问”:它竟然懂得抠细节! 4. 交棒时刻:从“设计”到“施工” 5. 关键技巧:如何“一键授权”所有文件? 6. 见证成果 第四部分:结语 在之前的教程中,我们成功在 Windows 11