数据分析

extractor

试用

Extract structured data from HTML pages or URLs using CSS selectors, XPath, regex, or LLM natural...

它能做什么

Extract structured data from HTML pages or URLs using CSS selectors, XPath, regex, or LLM natural...

技能文档

Extractor - 结构化字段提取器

�?HTML 页面中提取结构化字段,输�?JSON 格式。支持四种提取方式:CSS / XPath / Regex / LLM�?

快速开�?

from scripts.extractor import PageExtractor, load_html

# �?URL 加载
html = load_html("https://example.com")

# 或从文件加载
html = load_html("page.html")

# 创建提取�?ext = PageExtractor(html)

# CSS 提取
result = ext.extract_by_css({
    "title": "h1",
    "price": ".price",
    "links": {"selector": "a", "attr": "href", "all": True}
})

# XPath 提取
result = ext.extract_by_xpath({
    "titles": "//h1/text()",
    "emails": "//a[contains(@href,'mailto')]/@href"
})

# 正则提取
result = ext.extract_by_regex({
    "phone": {"pattern": r"1[3-9]\d{9}", "all": False},
    "emails": r"[\w.]+@[\w.]+"
})

# 混合提取
result = ext.extract_all(
    css={"title": "h1"},
    xpath={"specs": "//li/text()"},
    regex={"phone": r"1\d{10}"}
)

CLI 用法

# �?URL 提取
python scripts/extractor.py --url "https://example.com" --css '{"title": "h1"}' --pretty

# 从文件提�?python scripts/extractor.py --file page.html --xpath '{"links": "//a/@href"}' --pretty

# 混合提取
python scripts/extractor.py --file page.html \
    --css '{"title": "h1"}' \
    --regex '{"phone": "1[3-9]\\d{9}"}' \
    --pretty -o result.json

配置格式

CSS 选择�?

简单格式(字符串)�?```json {"title": "h1.product-title"}


完整格式(dict):
```json
{
    "title": {"selector": "h1", "text": true},
    "link": {"selector": "a.btn", "attr": "href"},
    "items": {"selector": "li.item", "all": true}
}
参数类型默认�?说明
selectorstr-CSS 选择�?
attrstrnull提取属性(href/src/class 等)
allboolfalse是否返回所有匹�?
textbooltrue是否提取文本

XPath

简单格式(字符串)�?```json {"titles": "//h1/text()"}


完整格式(dict):
```json
{
    "first_title": {"xpath": "//h1/text()", "all": false},
    "all_links": {"xpath": "//a/@href", "all": true}
}

正则表达�?

简单格式(字符串)�?```json {"emails": "[\w.]+@[\w.]+"}


完整格式(dict):
```json
{
    "phone": {"pattern": "1[3-9]\\d{9}", "all": false},
    "price": {"pattern": "¥(\\d+\\.\\d{2})", "all": true},
    "email_ci": {"pattern": "admin@site", "ignorecase": true}
}
参数类型默认�?说明
patternstr-正则表达�?
allbooltrue是否返回所有匹�?
ignorecaseboolfalse忽略大小�?
multilineboolfalse多行模式
dotallboolfalseDOTALL 模式

输出格式

所有方法返�?{字段�? 值} �?JSON 映射�?- 单个值:字符�?- 多个值:字符串列�?- 无匹配:null

依赖

pip install beautifulsoup4 lxml playwright
playwright install chromium  # �?URL 模式需�?```

## 限制

- LLM 提取尚未实现(标记为 TODO�?- URL 模式需�?Playwright + Chromium
- 大页面建议先裁剪 HTML 再提�?
## 详细文档

参见 [references/usage.md](references/usage.md)

相关技能

Extract structured data from web content using the Scrapfly Extraction API with the Python SDK

Run explicit Extruct API tasks through the bundled Extruct CLI. Covers Deep Search, semantic search, lookalike search, company and people tables, column oper...

12 次安装

Web extraction for LLMs and agents. Scrape, crawl, map, search, extract, summarize, diff, monitor, and research any URL into clean Markdown, text, or JSON, i...

3 次安装

Extract and clean readable article content, metadata, and markdown from URLs or HTML for research, note taking, and web scraping.

66 次安装1 星标

Extract reusable code snippets, API patterns, and configuration examples from web pages. Use when you find a documentation page, blog post, or tutorial and need to pull out the actionable code blocks, CLI commands, or config snippets without manually scanning the entire page.

Extract structured JSON from web pages, search engines, and entire sites in ONE call — {title, summary, sections, key_metrics, outgoing_links, author, date, page_type, ...} fields, no second LLM pass to parse HTML. Six endpoints: scrape (single URL), scrape-interactive (JS-rendered pages with click/scroll/type), search (Google SERP + deep-scrape), map (URL discovery), crawl + crawl-status (async recursive crawl). Markdown/raw HTML on request. USE when the user needs page DATA — product pricing/specs, article fields, link graphs, JS-heavy SPAs, Google results with content. Prefer over browser-act (automation/screenshots) and WebFetch (static, no JS, no structured fields). Not for citation-rich research (use deep-research). Trigger (EN): scrape this URL, extract data from page, crawl this site, deep-scrape search results, map a domain's URLs, render this JS page. 触发词:抓取/爬取/网页提取/结构化抽取/搜索带内容/全站爬取/JS 渲染抓取/点击后抓取. Requires ZOODATA_API_KEY (free key: https://zoodata.ai/en/api-keys).