Pipeline-based web content extraction library
Project description
WebData Extractor
Pipeline-based web content extraction library for extracting company information and metadata from web pages.
🚀 Features
- Pipeline Architecture: Modular architecture with independent processors
- Extensibility: Easy to add new processors without modifying existing code
- Auto-Discovery: Automatic discovery of processors in the folder
- Prioritization: Control processor execution order
- Conditional Execution: Processors can execute conditionally
- Error Handling: Pipeline continues working even if individual processors fail
📦 Installation
pip install -e .
Or for development:
pip install -e ".[dev]"
🔧 Usage
Simple Usage
from web_extractor import extract_company_info
# Extract company information
result = extract_company_info("example.com")
print(result["domain"]) # Domain
print(result["metadata"]["og:site_name"]) # Company name (if available)
print(result["metadata"]) # All metadata
With Processor Selection
from web_extractor import extract_company_info
# Use only standard processors
result = extract_company_info("example.com", use_all_processors=False)
# Or automatically discover all processors (default)
result = extract_company_info("example.com", use_all_processors=True)
Advanced Usage
from web_extractor import fetch_url, Pipeline
from web_extractor.processors import (
MetaTagsProcessor,
TitleProcessor,
CustomProcessor # Your custom processor
)
# Fetch HTML
data = fetch_url("example.com")
# Configure pipeline
pipeline = Pipeline()
pipeline.add_processors([
MetaTagsProcessor(),
TitleProcessor(),
CustomProcessor(),
])
# Execute processing
result = pipeline.execute(data, data["soup"], data["html"])
Auto-Discovery
from web_extractor import discover_processors, extract_with_auto_discovery
# Show all discovered processors
processors = discover_processors()
for proc in sorted(processors, key=lambda p: p.priority):
print(f"[{proc.priority:3d}] {proc.name}")
# Use all discovered processors
result = extract_with_auto_discovery("example.com")
🔌 Creating a Custom Processor
- Create a file in
web_extractor/processors/my_processor.py:
from typing import Any, Dict
from bs4 import BeautifulSoup
from web_extractor.pipeline import DataProcessor
class MyProcessor(DataProcessor):
@property
def name(self) -> str:
return "my_processor"
@property
def priority(self) -> int:
return 60 # Execution priority
def process(self, data: Dict[str, Any], soup: BeautifulSoup, html: str) -> Dict[str, Any]:
# Your processing logic
meta_tag = soup.find("meta", attrs={"name": "custom-tag"})
if meta_tag:
content = meta_tag.get("content")
if content:
data["metadata"]["custom_data"] = str(content)
return data
- Add to
web_extractor/processors/__init__.py:
from .my_processor import MyProcessor
__all__ = [
# ... others
'MyProcessor',
]
- Done! The processor will execute automatically.
📊 Result Structure
{
"url": "https://example.com",
"domain": "example.com",
"metadata": {
"og:site_name": "Example Company",
"og:title": "Example - Home",
"og:description": "...",
"twitter:site": "examplecom",
"title_raw": "Example Company - Official Site",
"title": "Example Company",
"description": "...",
"copyright": {...},
# ... other metadata
},
"processors_executed": [
"meta_tags",
"title",
"copyright",
"domain_fallback"
]
}
🎯 Existing Processors
| Priority | Processor | Description |
|---|---|---|
| 10 | meta_tags | All meta tags (OpenGraph, Twitter, Dublin Core, Apple, Microsoft, Facebook, Article, etc.) |
| 30 | title | HTML title, application-name, title variants, title parts |
| 40 | copyright | Copyright from text, meta tags, schema.org, footer, link rel |
| 999 | domain_fallback | Fallback to domain name |
📝 Examples
See the examples/ folder for complete examples:
examples/basic_usage.py- Basic usageexamples/custom_processor.py- Creating a custom processorexamples/advanced_pipeline.py- Advanced pipeline configuration
🧪 Testing
# Run tests
pytest
# With coverage
pytest --cov=web_extractor --cov-report=html
📄 License
MIT License
🤝 Contributing
Contributions are welcome! Please create an issue or pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file webdata_extractor-1.0.0.tar.gz.
File metadata
- Download URL: webdata_extractor-1.0.0.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c813d79e992eedcf9781468aac2b44fe930f801af214c97584a5f050cecc365c
|
|
| MD5 |
26e398044793dab487962b989d3ab9a6
|
|
| BLAKE2b-256 |
0e30ca18e90f37bd289d616bc43e31894c3096051a4365c7f22d0bd95e65a491
|
File details
Details for the file webdata_extractor-1.0.0-py3-none-any.whl.
File metadata
- Download URL: webdata_extractor-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
035b22ca5cfd19ddb7efea70791d3658b843ab1c265ed84c9b98e3c05d866fad
|
|
| MD5 |
cf99588a722f1f8ebb5de1b9f49dd071
|
|
| BLAKE2b-256 |
8dd96114d15d6cbdf8f804b927ae438444e54178dcefe50e7c20fb5562478fda
|