data-extractor
БесплатноБез исполняемых скриптовНе проверенExtract structured data from any document format using unified document processing. Use when a user asks to extract data from a document, parse a PDF, pull…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Data Extractor
Overview
Extract structured data from documents in any format: PDF, DOCX, HTML, TXT, images, and more, using plain Python libraries (pdfplumber, PyMuPDF, python-docx, BeautifulSoup, Tesseract OCR). Converts unstructured or semi-structured content into clean JSON, CSV, or other structured formats. Handles invoices, forms, reports, and free-text documents.
Instructions
When a user asks you to extract data from a document, follow this process:
Step 1: Identify the document format and install dependencies
# Determine file type
file document.pdf
# Install dependencies based on format
pip install pdfplumber python-docx beautifulsoup4 lxml openpyxl pymupdf
Library selection by format:
- PDF:
pdfplumber(text + tables),PyMuPDF(import pymupdf, older code usesimport fitz) for complex layouts and speed - DOCX:
python-docx - HTML:
beautifulsoup4withlxml - Excel:
openpyxlorpandas - Images / scans:
pytesseractwithPillow; it only wraps the Tesseract program, which must be installed separately (apt install tesseract-ocr,brew install tesseract) - JSON/XML: Python standard library
Step 2: Extract raw content
PDF extraction:
import pdfplumber
with pdfplumber.open("document.pdf") as pdf:
for i, page in enumerate(pdf.pages):
text = page.extract_text()
print(f"--- Page {i+1} ---")
print(text)
# Extract tables if present
tables = page.extract_tables()
for table in tables:
for row in table:
print(row)
DOCX extraction:
from docx import Document
doc = Document("document.docx")
for para in doc.paragraphs: # body paragraphs only; tables are not included here
print(f"[{para.style.name}] {para.text}")
# Extract tables (merged cells come back repeated)
for table in doc.tables:
for row in table.rows:
print([cell.text for cell in row.cells])
HTML extraction:
from bs4 import BeautifulSoup
with open("document.html", encoding="utf-8") as f:
soup = BeautifulSoup(f, "lxml")
# Extract specific elements
for table in soup.find_all("table"):
rows = table.find_all("tr")
for row in rows:
cells = [td.get_text(strip=True) for td in row.find_all(["td", "th"])]
print(cells)
Step 3: Parse and structure the data
Once you have raw text, extract the target fields:
Pattern-based extraction:
import re
import json
text = "..." # extracted text
# Define patterns for common fields
patterns = {
"invoice_number": r"Invoice\s*#?\s*:?\s*(\w+[-/]?\w+)",
"date": r"Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})",
"total": r"(?<![A-Za-z])Total\s*(?:due)?\s*:?\s*\$?([\d,]+\.?\d*)", # skips "Subtotal"
"email": r"[\w.-]+@[\w.-]+\.\w+",
}
extracted = {}
for field, pattern in patterns.items():
match = re.search(pattern, text, re.IGNORECASE)
if match:
extracted[field] = match.group(1) if match.lastindex else match.group(0)
print(json.dumps(extracted, indent=2))
Line-item extraction from tables:
import pandas as pd
# From a list of table rows
headers = table_data[0]
rows = table_data[1:]
df = pd.DataFrame(rows, columns=headers)
# Clean up
df.columns = df.columns.str.strip().str.lower().str.replace(" ", "_")
df = df.dropna(how="all")
Step 4: Validate and clean the output
# Type conversion
extracted["total"] = float(extracted["total"].replace(",", ""))
# Date normalization
from datetime import datetime
extracted["date"] = datetime.strptime(extracted["date"], "%m/%d/%Y").isoformat()
# Validate required fields
required = ["invoice_number", "date", "total"]
missing = [f for f in required if f not in extracted]
if missing:
print(f"Warning: missing fields: {missing}")
Step 5: Output in the desired format
# JSON output
with open("extracted_data.json", "w") as f:
json.dump(extracted, f, indent=2)
# CSV output
df.to_csv("extracted_items.csv", index=False)
# Pretty print summary
print(f"Extracted {len(extracted)} fields from document")
print(f"Line items: {len(df)} rows")
Examples
Example 1: Extract invoice data from a PDF
User request: "Extract the invoice details from this PDF"
Actions:
- Open the PDF with pdfplumber and extract text
- Use regex patterns to find invoice number, date, vendor, subtotal, tax, total
- Extract the line items table into a DataFrame
- Output a JSON file with header fields and a CSV with line items
Output:
{
"invoice_number": "INV-2025-0042",
"date": "2025-03-15",
"vendor": "Northwind Traders",
"subtotal": 1250.00,
"tax": 100.00,
"total": 1350.00,
"line_items": [
{"description": "Steel bracket, 40 mm", "qty": 10, "unit_price": 75.00, "amount": 750.00},
{"description": "Mounting plate", "qty": 5, "unit_price": 100.00, "amount": 500.00}
]
}
Example 2: Extract cont
Установить data-extractor в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл data-extractor?
Extract structured data from any document format using unified document processing. Use when a user asks to extract data from a document, parse a PDF, pull structured data from files, convert documents to JSON or CSV, extract fields from invoices or forms, or scrape data from documents.
Как установить скилл data-extractor?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл data-extractor запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic