mcpField
E
extract-page-data

extract-page-data

github.com/lintendo设计与 UI137140 次安装3 天前更新
代码仓库

关于 extract-page-data

extract-page-data 是用于采集网页内容与设计信息的命令行技能,可导出截图、设计令牌、Markdown 文本和交互元素,并支持按选择器限定提取范围。

主要功能

  1. 01截取整页或指定元素
  2. 02提取 CSS 设计令牌
  3. 03将页面内容转为 Markdown
  4. 04收集链接和交互元素
  5. 05将结果打包为 ZIP 数据包

适用场景

  1. 01检查网站的视觉设计
  2. 02根据设计令牌重建页面
  3. 03检查页面内容和控件
  4. 04采集需登录或含懒加载内容的页面

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/lintendo/axhub-skills --skill extract-page-data

安装后在 Claude Code 中输入/extract-page-data确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

scripts/
extract.mjs
scripts/inject/
extract-links.js
extract-markdown.js
extract-theme.js
README.md
scripts/lib/
browser.mjs
links.mjs
markdown.mjs
pack.mjs
screenshot.mjs
theme.mjs

详细介绍

提取页面数据

从任意网页提取结构化数据,用于设计分析、页面重建或内容审核。脚本会自动安装依赖项——只需提供网址即可。

适用场景

  • 用户分享网页 URL 并想要截取页面
  • 用户想从页面提取设计令牌、CSS 主题或配色方案
  • 用户想将页面内容转换为 Markdown 文本
  • 用户想了解页面上有哪些链接、按钮和交互元素
  • 用户要求导出或分析任意网页的结构
  • 用户想截取页面上的特定元素(使用 --selector)

请勿用于 Axure 原型——请改用 extract-axure-data。

快速开始

从相对于此技能目录的 scripts/extract.mjs 运行提取脚本。

# Full page screenshot
node scripts/extract.mjs https://example.com --screenshot

# Screenshot of a specific element
node scripts/extract.mjs https://example.com --screenshot --selector "#hero"

# Extract design tokens (colors, typography, spacing, etc.)
node scripts/extract.mjs https://example.com --theme

# Extract page content as Markdown
node scripts/extract.mjs https://example.com --markdown

# Collect all links and interactive elements
node scripts/extract.mjs https://example.com --links

# Extract everything
node scripts/extract.mjs https://example.com --all

# Export full data pack (screenshot + theme + markdown + links as zip)
node scripts/extract.mjs https://example.com --pack

首次运行时会自动将 Playwright + Chromium 安装到 ~/.cache/page-extractor/。这需要 1-2 分钟,且只会进行一次。

参数

标志功能默认值
<url>网页 URL(必需)—
--screenshot截取页面关闭
--theme提取设计令牌关闭
--markdown将页面转换为 Markdown关闭
--links收集交互元素关闭
--pack导出完整数据包(zip)关闭
--all运行所有提取任务关闭
--selector SEL用于限定提取范围的 CSS 选择器整个页面
-o DIR输出目录./page-export
--viewport WxH视口大小1280x720
--wait MS页面加载后的额外等待时间(ms)0
--scroll滚动页面以触发延迟加载的内容关闭
--scroll-step PX每次滚动的像素数800
--scroll-delay MS两次滚动之间的延迟(ms)200
--no-headless显示浏览器窗口无头模式
--connect-cdp URL连接到正在运行的 Chrome(用于身份验证)—
--format FMT截图格式:png 或 jpegpng
--verbose详细日志关闭

输出结构

page-export/
├── screenshot.png       # Page or element screenshot    (--screenshot)
├── theme.json           # Design tokens                 (--theme)
├── content.md           # Page text as Markdown          (--markdown)
├── links.json           # Links and interactive elements (--links)
└── page-data.zip        # Full data pack                 (--pack)
    ├── screenshot.png
    ├── theme.json
    ├── content.md
    ├── links.json
    └── meta.json        # Page metadata (title, url, viewport)

选择器支持

所有提取模式都支持使用 --selector 将范围限定到特定元素:

# Screenshot only the header
node scripts/extract.mjs https://example.com --screenshot --selector "header"

# Extract design tokens from a card component
node scripts/extract.mjs https://example.com --theme --selector ".card"

# Get Markdown from the main content area
node scripts/extract.mjs https://example.com --markdown --selector "main"

# Collect links from the navigation
node scripts/extract.mjs https://example.com --links --selector "nav"

需要身份验证的页面

有些页面需要登录。可使用以下两种方法:

连接到现有 Chrome 会话(推荐——重用 Cookie):

macOS:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

Windows:

start chrome --remote-debugging-port=9222

然后在该 Chrome 窗口中登录,再运行:

node scripts/extract.mjs https://example.com --all --connect-cdp http://localhost:9222

显示浏览器窗口(提取期间手动登录):

node scripts/extract.mjs https://example.com --all --no-headless

依赖项安装

脚本会在首次运行时自动安装依赖项。如果安装失败:

# Manual install
cd ~/.cache/page-extractor
npm install playwright
npx playwright install chromium

# If Chromium download is slow (e.g. behind GFW):
PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright npx playwright install chromium

输出数据格式

theme.json

从计算后的 CSS 样式中提取的设计系统令牌:

{
  "colors": {
    "background": [{"value": "rgb(255,255,255)", "count": 42, "tags": ["div"]}],
    "text": [{"value": "rgb(51,51,51)", "count": 28, "tags": ["p","span"]}],
    "border": [{"value": "rgb(221,221,221)", "count": 12}]
  },
  "typography": {
    "families": [{"value": "\"Inter\", sans-serif", "count": 56}],
    "textStyles": [{"size": "14px", "lineHeight": "22px", "weight": "400", "count": 20}]
  },
  "spacing": [{"value": "16px", "count": 15}],
  "radius": [{"value": "4px", "count": 8}],
  "lineWidth": [{"value": "1px", "count": 10}],
  "shadow": {
    "box": [{"value": "0 2px 8px rgba(0,0,0,0.1)", "count": 5}],
    "text": []
  },
  "transitions": [{"value": "all 0.2s ease", "count": 38, "tags": ["button","a"]}],
  "animations": [{"value": "fadeIn|0.3s|ease", "count": 5, "tags": ["div"]}],
  "cssVariables": {
    "--color-primary": "#6366f1",
    "--radius": "0.5rem",
    "--font-sans": "Inter, sans-serif"
  },
  "assets": {
    "backgroundImages": [{"value": "url(hero.webp)", "count": 1, "tags": ["section"]}],
    "images": [
      {"src": "https://example.com/logo.svg", "alt": "Logo", "position": "static", "zIndex": "auto", "siblingImgCount": 1},
      {"src": "https://example.com/hero.png", "alt": "", "position": "absolute", "zIndex": "2", "siblingImgCount": 2}
    ],
    "svgCount": 12
  }
}
links.json

页面上的交互元素:

{
  "pageUrl": "https://example.com",
  "pageTitle": "Example",
  "links": [
    {"type": "a", "text": "Home", "href": "https://example.com/", "visible": true},
    {"type": "button", "text": "Sign Up", "visible": true},
    {"type": "form", "href": "https://example.com/login", "visible": true}
  ],
  "totalLinks": 3,
  "visibleLinks": 3
}

自定义

提取逻辑采用模块化设计。每项功能都位于 scripts/ 下独立的文件中:

文件用途自定义内容
lib/browser.mjsPlaywright 浏览器管理更改浏览器启动参数、代理
lib/screenshot.mjs截图修改滚动行为、格式
lib/theme.mjs设计令牌提取调整令牌类别、数量上限
lib/markdown.mjsHTML → Markdown更改转换规则
lib/links.mjs元素收集添加新的元素类型
lib/pack.mjsZip 打包更改数据包内容
inject/extract-theme.js注入浏览器的主题逻辑修改要提取的 CSS 属性
inject/extract-markdown.js注入浏览器的 Markdown 逻辑自定义文本提取
inject/extract-links.js注入浏览器的链接逻辑添加自定义选择器

主题克隆工作流

当用户想克隆或复刻网站的设计语言时,请按以下顺序运行:

步骤 1:提取所有数据
node extract.mjs <url> --all --scroll --viewport 1440x900
步骤 2:解读 theme.json
字段对应项CSS 变量
colors.background[0]主表面--color-bg
colors.text[0]正文--color-text
colors.text[1]强调色 / 品牌色--color-primary
typography.families[0]主字体Google Fonts 导入
spacing(前 5 项)间距比例--spacing-1 …
radius[0]默认圆角--radius-base
transitions[0]悬停时长应用于 .card, a, button
cssVariables设计令牌(如果存在 :root 变量)直接使用变量名
步骤 3:生成 CSS 变量
:root {
  --color-bg:       <colors.background[0].value>;
  --color-text:     <colors.text[0].value>;
  --color-primary:  <colors.text[1].value>;
  --font-sans:      <typography.families[0].value>;
  --radius-base:    <radius[0].value>;
  --transition:     <transitions[0].value>;
}

如果 cssVariables 非空,优先使用其中的变量名——它们体现了原始设计系统的意图。

步骤 4:还原动画
  • transitions[0].value → 在交互元素上应用为 transition: <value>
  • animations → 按动画名称重建 @keyframes 块;应用于进入页面的元素
步骤 5:处理分层素材

在 assets.images 中,position: absolute 且 zIndex > 0 的图像属于叠加层。 使用父元素的 CSS position: relative 和叠加层的 position: absolute 进行还原。

使用 Playwright 查缺补漏

导出数据是尽力而为的快照,有时需要返回原始页面补充信息(例如悬停态样式、懒加载内容、动画效果等)。可使用 Playwright CLI 进行交互式补充采集。

# 打开页面并获取快照
playwright-cli open https://example.com
playwright-cli snapshot

# 交互后采集(如 hover 态)
playwright-cli hover e15
playwright-cli screenshot --filename=hover-state.png

# 获取元素属性
playwright-cli eval "el => getComputedStyle(el).backdropFilter" e5

playwright-cli close

完整命令参考:Playwright CLI 官方技能文档

何时需要 Playwright
场景Playwright 的用途
截图模糊/不完整对指定元素进行高分辨率截图
样式数据缺失获取完整的 computedStyle
hover/focus/active 状态触发交互后采集样式
懒加载内容滚动触发后截图
动画/过渡效果定时截图或录屏
响应式断点校验设置 viewport 后截图

故障排除

问题解决方法
截图为空白页面需要时间渲染——添加 --wait 2000
缺少懒加载内容使用 --scroll 触发懒加载
需要登录使用 --connect-cdp(参见上文“已认证页面”)
Playwright 安装失败手动安装,或设置 PLAYWRIGHT_DOWNLOAD_HOST
选择了错误的元素先用浏览器 DevTools 检查选择器

评论

支持 Markdown