mcpField
X
xcrawl-scrape

xcrawl-scrape

github.com/xcrawl-api数据与数据库450243 次安装32 周前更新
代码仓库

关于 xcrawl-scrape

xcrawl-scrape 是通过 XCrawl Scrape API 抽取单个页面数据的技能。它支持配置请求和输出选项、同步或异步执行,并默认原样返回 API 响应。

主要功能

  1. 01单页 URL 抽取
  2. 02同步与异步执行
  3. 03可配置请求和渲染
  4. 04支持 HTML、Markdown、链接、JSON 等
  5. 05原样传递响应

适用场景

  1. 01抽取指定页面的内容
  2. 02请求结构化 JSON 字段
  3. 03获取页面截图或链接
  4. 04轮询异步抓取结果

安装

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

$npx skills add https://github.com/xcrawl-api/xcrawl-skills --skill xcrawl-scrape

安装后在 Claude Code 中输入/xcrawl-scrape确认已加载。

详细介绍

XCrawl Scrape

概述

此技能使用 XCrawl Scrape API 提取单个页面。 默认行为是原样透传:直接返回上游 API 响应正文。

必需的本地配置

使用此技能前,用户必须创建本地配置文件,并在其中写入 XCRAWL_API_KEY。

路径:~/.xcrawl/config.json

{
  "XCRAWL_API_KEY": "<your_api_key>"
}

只能从本地配置文件读取 API 密钥。不要要求设置全局环境变量。

额度与账户设置

使用 XCrawl API 会消耗额度。 如果用户没有账户或可用额度,请引导他们前往 https://dash.xcrawl.com/ 注册。 注册后,他们可以在发起请求前激活免费的 1000 额度套餐。

工具权限策略

仅请求 curl 和 node 的运行时权限。 不要请求 Python、Shell 辅助脚本或其他运行时权限。

API 接口

  • 开始抓取:POST /v1/scrape
  • 读取异步结果:GET /v1/scrape/{scrape_id}
  • 基础 URL:https://run.xcrawl.com
  • 必需的请求头:Authorization: Bearer <XCRAWL_API_KEY>

使用示例

cURL(同步)
API_KEY="$(node -e "const fs=require('fs');const p=process.env.HOME+'/.xcrawl/config.json';const k=JSON.parse(fs.readFileSync(p,'utf8')).XCRAWL_API_KEY||'';process.stdout.write(k)")"

curl -sS -X POST "https://run.xcrawl.com/v1/scrape" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${API_KEY}" \
  -d '{"url":"https://example.com","mode":"sync","output":{"formats":["markdown","links"]}}'
cURL(创建异步任务并获取结果)
API_KEY="$(node -e "const fs=require('fs');const p=process.env.HOME+'/.xcrawl/config.json';const k=JSON.parse(fs.readFileSync(p,'utf8')).XCRAWL_API_KEY||'';process.stdout.write(k)")"

CREATE_RESP="$(curl -sS -X POST "https://run.xcrawl.com/v1/scrape" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${API_KEY}" \
  -d '{"url":"https://example.com/product/1","mode":"async","output":{"formats":["json"]},"json":{"prompt":"Extract title and price."}}')"

echo "$CREATE_RESP"

SCRAPE_ID="$(node -e 'const s=process.argv[1];const j=JSON.parse(s);process.stdout.write(j.scrape_id||"")' "$CREATE_RESP")"

curl -sS -X GET "https://run.xcrawl.com/v1/scrape/${SCRAPE_ID}" \
  -H "Authorization: Bearer ${API_KEY}"
Node
node -e '
const fs=require("fs");
const apiKey=JSON.parse(fs.readFileSync(process.env.HOME+"/.xcrawl/config.json","utf8")).XCRAWL_API_KEY;
const body={url:"https://example.com",mode:"sync",output:{formats:["markdown","json"]},json:{prompt:"Extract title and publish date."}};
fetch("https://run.xcrawl.com/v1/scrape",{
  method:"POST",
  headers:{"Content-Type":"application/json",Authorization:`Bearer ${apiKey}`},
  body:JSON.stringify(body)
}).then(async r=>{console.log(await r.text());});
'

请求参数

请求端点和请求头
  • 端点:POST https://run.xcrawl.com/v1/scrape
  • 请求头:
  • Content-Type: application/json
  • Authorization: Bearer <api_key>
请求正文:顶层字段
字段类型必填默认值说明
urlstring是-目标 URL
modestring否syncsync 或 async
proxyobject否-代理配置
requestobject否-请求配置
js_renderobject否-JS 渲染配置
outputobject否-输出配置
webhookobject否-异步 Webhook 配置(mode=async)
proxy
字段类型必填默认值说明
locationstring否USISO-3166-1 alpha-2 国家代码,例如 US / JP / SG
sticky_sessionstring否自动生成粘性会话 ID;使用相同 ID 会尝试复用出口
request
字段类型必填默认值说明
localestring否en-US,en;q=0.9影响 Accept-Language
devicestring否desktopdesktop / mobile;影响 UA 和视口
cookiesobject map否-Cookie 键值对
headersobject map否-请求头键值对
only_main_contentboolean否true仅返回主要内容
block_adsboolean否true尝试屏蔽广告资源
skip_tls_verificationboolean否true跳过 TLS 验证
js_render
字段类型必填默认值说明
enabledboolean否true启用浏览器渲染
wait_untilstring否loadload / domcontentloaded / networkidle
viewport.widthinteger否-视口宽度(桌面端为 1920,移动端为 402)
viewport.heightinteger否-视口高度(桌面端为 1080,移动端为 874)
output
字段类型必填默认值说明
formatsstring[]否["markdown"]输出格式
screenshotstring否viewportfull_page / viewport(仅当 formats 包含 screenshot 时)
json.promptstring否-提取提示词
json.json_schemaobject否-JSON Schema

output.formats 枚举值:

  • html
  • raw_html
  • markdown
  • links
  • summary
  • screenshot
  • json
webhook
字段类型必填默认值说明
urlstring否-回调 URL
headersobject map否-自定义回调请求头
eventsstring[]否["started","completed","failed"]事件:started / completed / failed

响应参数

同步创建响应(mode=sync)
字段类型描述
scrape_idstring任务 ID
endpointstring始终为 scrape
versionstring版本
statusstringcompleted / failed
urlstring目标 URL
dataobject结果数据
started_atstring开始时间(ISO 8601)
ended_atstring结束时间(ISO 8601)
total_credits_usedinteger使用的总额度

data 字段(基于 output.formats):

  • html、raw_html、markdown、links、summary、screenshot、json
  • metadata(页面元数据)
  • traffic_bytes
  • credits_used
  • credits_detail

credits_detail 字段:

字段类型描述
base_costinteger基础抓取费用
traffic_costinteger流量费用
json_extract_costintegerJSON 提取费用
异步创建响应(mode=async)
字段类型描述
scrape_idstring任务 ID
endpointstring始终为 scrape
versionstring版本
statusstring始终为 pending
异步结果响应(GET /v1/scrape/{scrape_id})
字段类型描述
scrape_idstring任务 ID
endpointstring始终为 scrape
versionstring版本
statusstringpending / crawling / completed / failed
urlstring目标 URL
dataobject与同步 data 结构相同
started_atstring开始时间(ISO 8601)
ended_atstring结束时间(ISO 8601)

工作流

  1. 将用户目标重述为提取约定。
  • URL 范围、必需字段、可接受的空值以及精度要求。
  1. 构建抓取请求正文。
  • 仅保留必要选项。
  • 优先明确指定 output.formats。
  1. 执行抓取并记录任务元数据。
  • 跟踪 scrape_id、status 和时间戳。
  • 如果为异步模式,则轮询直至状态变为 completed 或 failed。
  1. 直接返回原始 API 响应。
  • 默认不要合成或压缩字段。

输出约定

返回:

  • 使用的端点和模式(sync 或 async)
  • 请求使用的 request_payload
  • 每次 API 调用的原始响应正文
  • 请求失败时的错误详情

除非用户明确要求摘要,否则不要生成摘要。

防护措施

  • 不要编造不受支持的输出字段。
  • 不要在核心逻辑中硬编码特定提供商的工具架构。
  • 页面结构不稳定时,说明不确定性。

评论

支持 Markdown