{"data":{"slug":"github-claude-office-skills-skills-data-extractor-ec0bb9d1f38e","title":"Data Extractor: Extract Structured Data from Documents","summary":"Extract structured data from PDFs, Word docs, emails, HTML, and more using unstructured. Get consistent, structured output regardless of input format.","url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-data-extractor-ec0bb9d1f38e","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-claude-office-skills-skills-data-extractor-ec0bb9d1f38e","markdown_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-data-extractor-ec0bb9d1f38e.md","download_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-data-extractor-ec0bb9d1f38e\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Install unstructured with `pip install unstructured` or `pip install \"unstructured[all-docs]\"` for full functionality. Ensure the document is accessible and compatible with supported formats (PDF, Word, email, HTML, etc.).","instructions":"---\n# \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n# CLAUDE OFFICE SKILL - Enhanced Metadata v2.0\n# \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n# Basic Information\nname: data-extractor\ndescription: \">\"\nversion: \"1.0\"\nauthor: claude-office-skills\nlicense: MIT\n\n# Categorization\ncategory: parsing\ntags:\n  - extraction\n  - data\n  - unstructured\ndepartment: All\n\n# AI Model Compatibility\nmodels:\n  recommended:\n    - claude-sonnet-4\n    - claude-opus-4\n  compatible:\n    - claude-3-5-sonnet\n    - gpt-4\n    - gpt-4o\n\n# MCP Tools Integration\nmcp:\n  server: office-mcp\n  tools:\n    - extract_text_from_pdf\n    - extract_tables_from_pdf\n\n# Skill Capabilities\ncapabilities:\n  - data_extraction\n  - format_handling\n\n# Language Support\nlanguages:\n  - en\n  - zh\n---\n\n# Data Extractor Skill\n\n## Overview\n\nThis skill enables extraction of structured data from any document format using **unstructured** - a unified library for processing PDFs, Word docs, emails, HTML, and more. Get consistent, structured output regardless of input format.\n\n## How to Use\n\n1. Provide the document to process\n2. Optionally specify extraction options\n3. I'll extract structured elements with metadata\n\n**Example prompts:**\n- \"Extract all text and tables from this PDF\"\n- \"Parse this email and get the body, attachments, and metadata\"\n- \"Convert this HTML page to structured elements\"\n- \"Extract data from these mixed-format documents\"\n\n## Domain Knowledge\n\n### unstructured Fundamentals\n\n```python\nfrom unstructured.partition.auto import partition\n\n# Automatically detect and process any document\nelements = partition(\"document.pdf\")\n\n# Access extracted elements\nfor element in elements:\n    print(f\"Type: {type(element).__name__}\")\n    print(f\"Text: {element.text}\")\n    print(f\"Metadata: {element.metadata}\")\n```\n\n### Supported Formats\n\n| Format | Function | Notes |\n|--------|----------|-------|\n| PDF | `partition_pdf` | Native + scanned |\n| Word | `partition_docx` | Full structure |\n| PowerPoint | `partition_pptx` | Slides & notes |\n| Excel | `partition_xlsx` | Sheets & tables |\n| Email | `partition_email` | Body & attachments |\n| HTML | `partition_html` | Tags preserved |\n| Markdown | `partition_md` | Structure preserved |\n| Plain Text | `partition_text` | Basic parsing |\n| Images | `partition_image` | OCR extraction |\n\n### Element Types\n\n```python\nfrom unstructured.documents.elements import (\n    Title,\n    NarrativeText,\n    Text,\n    ListItem,\n    Table,\n    Image,\n    Header,\n    Footer,\n    PageBreak,\n    Address,\n    EmailAddress,\n)\n\n# Elements have consistent structure\nelement.text           # Raw text content\nelement.metadata       # Rich metadata\nelement.category       # Element type\nelement.id            # Unique identifier\n```\n\n### Auto Partition\n\n```python\nfrom unstructured.partition.auto import partition\n\n# Process any file type\nelements = partition(\n    filename=\"document.pdf\",\n    strategy=\"auto\",          # or \"fast\", \"hi_res\", \"ocr_only\"\n    include_metadata=True,\n    include_page_breaks=True,\n)\n\n# Filter by type\ntitles = [e for e in elements if isinstance(e, Title)]\ntables = [e for e in elements if isinstance(e, Table)]\n```\n\n### Format-Specific Partitioning\n\n```python\n# PDF with options\nfrom unstructured.partition.pdf import partition_pdf\n\nelements = partition_pdf(\n    filename=\"document.pdf\",\n    strategy=\"hi_res\",              # High quality extraction\n    infer_table_structure=True,     # Detect tables\n    include_page_breaks=True,\n    languages=[\"en\"],               # OCR language\n)\n\n# Word documents\nfrom unstructured.partition.docx import partition_docx\n\nelements = partition_docx(\n    filename=\"document.docx\",\n    include_metadata=True,\n)\n\n# HTML\nfrom unstructured.partition.html import partition_html\n\nelements = partition_html(\n    filename=\"page.html\",\n    include_metadata=True,\n)\n```\n\n### Working with Tables\n\n```python\nfrom unstructured.partition.auto import partition\n\nelements = partition(\"report.pdf\", infer_table_structure=True)\n\n# Extract tables\nfor element in elements:\n    if element.category == \"Table\":\n        print(\"Table found:\")\n        print(element.text)\n        \n        # Access structured table data\n        if hasattr(element, 'metadata') and element.metadata.text_as_html:\n            print(\"HTML:\", element.metadata.text_as_html)\n```\n\n### Metadata Access\n\n```python\nfrom unstructured.partition.auto import partition\n\nelements = partition(\"document.pdf\")\n\nfor element in elements:\n    meta = element.metadata\n    \n    # Common metadata fields\n    print(f\"Page: {meta.page_number}\")\n    print(f\"Filename: {meta.filename}\")\n    print(f\"Filetype: {meta.filetype}\")\n    print(f\"Coordinates: {meta.coordinates}\")\n    print(f\"Languages: {meta.languages}\")\n```\n\n### Chunking for AI\/RAG\n\n```python\nfrom unstructured.partition.auto import partition\nfrom unstructured.chunking.title import chunk_by_title\nfrom unstructured.chunking.basic import chunk_elements\n\n# Partition document\nelements = partition(\"document.pdf\")\n\n# Chunk by title (semantic chunks)\nchunks = chunk_by_title(\n    elements,\n    max_characters=1000,\n    combine_text_under_n_chars=200,\n)\n\n# Or basic chunking\nchunks = chunk_elements(\n    elements,\n    max_characters=500,\n    overlap=50,\n)\n\nfor chunk in chunks:\n    print(f\"Chunk ({len(chunk.text)} chars):\")\n    print(chunk.text[:100] + \"...\")\n```\n\n### Batch Processing\n\n```python\nfrom unstructured.partition.auto import partition\nfrom pathlib import Path\nfrom concurrent.futures import ThreadPoolExecutor\n\ndef process_document(file_path):\n    \"\"\"Process single document.\"\"\"\n    try:\n        elements = partition(str(file_path))\n        return {\n            'file': str(file_path),\n            'status': 'success',\n            'elements': len(elements),\n            'text': '\\n\\n'.join([e.text for e in elements])\n        }\n    except Exception as e:\n        return {\n            'file': str(file_path),\n            'status': 'error',\n            'error': str(e)\n        }\n\ndef batch_process(input_dir, max_workers=4):\n    \"\"\"Process all documents in directory.\"\"\"\n    input_path = Path(input_dir)\n    files = list(input_path.glob('*'))\n    \n    with ThreadPoolExecutor(max_workers=max_workers) as executor:\n        results = list(executor.map(process_document, files))\n    \n    return results\n```\n\n### Export Formats\n\n```python\nfrom unstructured.partition.auto import partition\nfrom unstructured.staging.base import elements_to_json, elements_to_dicts\n\nelements = partition(\"document.pdf\")\n\n# To JSON string\njson_str = elements_to_json(elements)\n\n# To list of dicts\ndicts = elements_to_dicts(elements)\n\n# To DataFrame\nimport pandas as pd\ndf = pd.DataFrame(dicts)\n```\n\n## Best Practices\n\n1. **Choose Strategy Wisely**: \"fast\" for speed, \"hi_res\" for accuracy\n2. **Enable Table Detection**: For documents with tables\n3. **Specify Language**: For better OCR on non-English docs\n4. **Chunk for RAG**: Use semantic chunking for AI applications\n5. **Handle Errors**: Some formats may fail gracefully\n\n## Common Patterns\n\n### Document to JSON\n```python\ndef document_to_json(file_path, output_path=None):\n    \"\"\"Convert document to structured JSON.\"\"\"\n    from unstructured.partition.auto import partition\n    from unstructured.staging.base import elements_to_json\n    import json\n    \n    elements = partition(file_path)\n    \n    # Create structured output\n    output = {\n        'source': file_path,\n        'elements': []\n    }\n    \n    for element in elements:\n        output['elements'].append({\n            'type': type(element).__name__,\n            'text': element.text,\n            'metadata': {\n                'page': element.metadata.page_number,\n                'coordinates': element.metadata.coordinates.to_dict() if element.metadata.coordinates else None\n            }\n        })\n    \n    if output_path:\n        with open(output_path, 'w') as f:\n            json.dump(output, f, indent=2)\n    \n    return output\n```\n\n### Email Parser\n```python\nfrom unstructured.partition.email import partition_email\n\ndef parse_email(email_path):\n    \"\"\"Extract structured data from email.\"\"\"\n    \n    elements = partition_email(email_path)\n    \n    email_data = {\n        'subject': None,\n        'from': None,\n        'to': [],\n        'date': None,\n        'body': [],\n        'attachments': []\n    }\n    \n    for element in elements:\n        meta = element.metadata\n        \n        # Extract headers from metadata\n        if meta.subject:\n            email_data['subject'] = meta.subject\n        if meta.sent_from:\n            email_data['from'] = meta.sent_from\n        if meta.sent_to:\n            email_data['to'] = meta.sent_to\n        \n        # Body content\n        email_data['body'].append({\n            'type': type(element).__name__,\n            'text': element.text\n        })\n    \n    return email_data\n```\n\n## Examples\n\n### Example 1: Research Paper Extraction\n```python\nfrom unstructured.partition.pdf import partition_pdf\nfrom unstructured.chunking.title import chunk_by_title\n\ndef extract_paper(pdf_path):\n    \"\"\"Extract structured data from research paper.\"\"\"\n    \n    elements = partition_pdf(\n        filename=pdf_path,\n        strategy=\"hi_res\",\n        infer_table_structure=True,\n        include_page_breaks=True\n    )\n    \n    paper = {\n        'title': None,\n        'abstract': None,\n        'sections': [],\n        'tables': [],\n        'references': []\n    }\n    \n    # Find title (usually first Title element)\n    for element in elements:\n        if element.category == \"Title\" and not paper['title']:\n            paper['title'] = element.text\n            break\n    \n    # Extract tables\n    for element in elements:\n        if element.category == \"Table\":\n            paper['tables'].append({\n                'page': element.metadata.page_number,\n                'content': element.text,\n                'html': element.metadata.text_as_html if hasattr(element.metadata, 'text_as_html') else None\n            })\n    \n    # Chunk into sections\n    chunks = chunk_by_title(elements, max_characters=2000)\n    \n    current_section = None\n    for chunk in chunks:\n        if chunk.category == \"Title\":\n            paper['sections'].append({\n                'title': chunk.text,\n                'content': ''\n            })\n        elif paper['sections']:\n            paper['sections'][-1]['content'] += chunk.text + '\\n'\n    \n    return paper\n\npaper = extract_paper('research_paper.pdf')\nprint(f\"Title: {paper['title']}\")\nprint(f\"Tables: {len(paper['tables'])}\")\nprint(f\"Sections: {len(paper['sections'])}\")\n```\n\n### Example 2: Invoice Data Extraction\n```python\nfrom unstructured.partition.auto import partition\nimport re\n\ndef extract_invoice_data(file_path):\n    \"\"\"Extract key data from invoice.\"\"\"\n    \n    elements = partition(file_path, strategy=\"hi_res\")\n    \n    # Combine all text\n    full_text = '\\n'.join([e.text for e in elements])\n    \n    invoice = {\n        'invoice_number': None,\n        'date': None,\n        'total': None,\n        'vendor': None,\n        'line_items': [],\n        'tables': []\n    }\n    \n    # Extract patterns\n    inv_match = re.search(r'Invoice\\s*#?\\s*:?\\s*(\\w+[-\\w]*)', full_text, re.I)\n    if inv_match:\n        invoice['invoice_number'] = inv_match.group(1)\n    \n    date_match = re.search(r'Date\\s*:?\\s*(\\d{1,2}[-\/]\\d{1,2}[-\/]\\d{2,4})', full_text, re.I)\n    if date_match:\n        invoice['date'] = date_match.group(1)\n    \n    total_match = re.search(r'Total\\s*:?\\s*\\$?([\\d,]+\\.?\\d*)', full_text, re.I)\n    if total_match:\n        invoice['total'] = float(total_match.group(1).replace(',', ''))\n    \n    # Extract tables\n    for element in elements:\n        if element.category == \"Table\":\n            invoice['tables'].append(element.text)\n    \n    return invoice\n\ninvoice = extract_invoice_data('invoice.pdf')\nprint(f\"Invoice #: {invoice['invoice_number']}\")\nprint(f\"Total: ${invoice['total']}\")\n```\n\n### Example 3: Document Corpus Builder\n```python\nfrom unstructured.partition.auto import partition\nfrom unstructured.chunking.title import chunk_by_title\nfrom pathlib import Path\nimport json\n\ndef build_corpus(input_dir, output_path):\n    \"\"\"Build searchable corpus from document collection.\"\"\"\n    \n    input_path = Path(input_dir)\n    corpus = []\n    \n    # Support multiple formats\n    patterns = ['*.pdf', '*.docx', '*.html', '*.txt', '*.md']\n    files = []\n    for pattern in patterns:\n        files.extend(input_path.glob(pattern))\n    \n    for file in files:\n        print(f\"Processing: {file.name}\")\n        \n        try:\n            elements = partition(str(file))\n            chunks = chunk_by_title(elements, max_characters=1000)\n            \n            for i, chunk in enumerate(chunks):\n                corpus.append({\n                    'id': f\"{file.stem}_{i}\",\n                    'source': str(file),\n                    'type': type(chunk).__name__,\n                    'text': chunk.text,\n                    'page': chunk.metadata.page_number if chunk.metadata.page_number else None\n                })\n        \n        except Exception as e:\n            print(f\"  Error: {e}\")\n    \n    # Save corpus\n    with open(output_path, 'w') as f:\n        json.dump(corpus, f, indent=2)\n    \n    print(f\"Corpus built: {len(corpus)} chunks from {len(files)} files\")\n    return corpus\n\ncorpus = build_corpus('.\/documents', 'corpus.json')\n```\n\n## Limitations\n\n- Complex layouts may need manual review\n- OCR quality depends on image quality\n- Large files may need chunking\n- Some proprietary formats not supported\n- API rate limits for cloud processing\n\n## Installation\n\n```bash\n# Basic installation\npip install unstructured\n\n# With all dependencies\npip install \"unstructured[all-docs]\"\n\n# For PDF processing\npip install \"unstructured[pdf]\"\n\n# For specific formats\npip install \"unstructured[docx,pptx,xlsx]\"\n```\n\n## Resources\n\n- [unstructured GitHub](https:\/\/github.com\/Unstructured-IO\/unstructured)\n- [Documentation](https:\/\/unstructured-io.github.io\/unstructured\/)\n- [Unstructured API](https:\/\/unstructured.io\/api-key)\n","use_cases":["Extract all text and tables from a PDF","Parse an email and get the body, attachments, and metadata","Convert an HTML page to structured elements","Extract data from mixed-format documents"],"limitations":[],"compatibility":[],"setup_tip":"```bash\n# Basic installation\npip install unstructured\n\n# With all dependencies\npip install \"unstructured[all-docs]\"\n\n# For PDF processing\npip install \"unstructured[pdf]\"\n\n# For specific formats\npip install \"unstructured[docx,pptx,xlsx]\"\n```","sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/claude-office-skills\/skills\/blob\/9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11\/data-extractor\/SKILL.md","source_commit":"9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11","license":"MIT","version":null,"listing_approved_at":"2026-11-22","created_at":"2026-11-21T13:20:04.000000Z","updated_at":"2026-11-22T11:17:55.000000Z","seo_title":"Extract Data from Any Document Format","seo_description":"Extract structured data from PDFs, Word docs, emails, HTML, and more. Get consistent, structured output with unstructured.","seo_keywords":["extract data from PDF","parse email content","convert HTML to structured data","extract text from document","structured data extraction"]}}