A data retrieval engine based on Playwright.
Project description
DR Web Engine
Modern, Query-Based Web Data Retrieval Engine
Transform any website into a structured data API with simple JSON5/YAML queries
DR Web Engine is a powerful, open-source data extraction engine that transforms web scraping from code-heavy scripts into simple, declarative queries. Define what you want to extract using JSON5 or YAML, and let the engine handle the complex browser automation and data extraction.
๐ Key Features
- ๐ฏ Query-Based Extraction: Define extractions in JSON5/YAML instead of writing scraping code
- ๐ค Browser Actions (NEW in v0.6+): Click, scroll, wait, fill forms - handle dynamic content
- ๐ง Conditional Logic (NEW in v0.7+): Smart branching based on page conditions and content
- โก Playwright-Powered: Reliable automation with modern browser engine
- ๐ Universal: Extract from any website - static or JavaScript-heavy SPAs
- ๐ Structured Output: Get clean JSON data ready for analysis
- ๐ง CLI & Docker: Run from command line or containerized environments
- ๐งช Thoroughly Tested: 95+ tests covering all functionality
๐ Table of Contents
- Quick Start
- Installation
- Basic Usage
- Action System
- Conditional Logic
- Query Keywords
- CLI Reference
- Real-World Examples
- Testing
- Documentation
- Contributing
๐ Quick Start
1. Install DR Web Engine
pip install dr-web-engine
2. Create a simple query (save as quotes.json5)
{
"@url": "https://quotes.toscrape.com",
"@steps": [
{
"@xpath": "//div[@class='quote']",
"@fields": {
"text": ".//span[@class='text']/text()",
"author": ".//small[@class='author']/text()",
"tags": ".//div[@class='tags']//a/text()"
}
}
]
}
3. Run the extraction
dr-web-engine -q quotes.json5 -o results.json
4. Get structured data
[
{
"text": "The world as we have created it is a process of our thinking...",
"author": "Albert Einstein",
"tags": ["change", "deep-thoughts", "thinking", "world"]
}
]
๐ฆ Installation
Option 1: Install from PyPI (Recommended)
pip install dr-web-engine
Option 2: Install from Source
git clone https://github.com/starlitlog/dr-web-engine.git
cd dr-web-engine
pip install -e .
Option 3: Docker
# Pull and run
docker run -v $(pwd)/data:/app/data drweb/dr-web-engine -q /app/data/query.json5 -o /app/data/output.json
# Or build locally
docker build -t dr-web-engine .
Install Playwright Browsers (Required)
playwright install
๐ก Basic Usage
Simple Extraction
Extract data using XPath selectors:
{
"@url": "https://news.ycombinator.com",
"@steps": [
{
"@xpath": "//tr[@class='athing']",
"@fields": {
"title": ".//span[@class='titleline']/a/text()",
"url": ".//span[@class='titleline']/a/@href",
"rank": ".//span[@class='rank']/text()"
}
}
]
}
With Pagination
Handle multi-page results:
{
"@url": "https://quotes.toscrape.com",
"@steps": [
{
"@xpath": "//div[@class='quote']",
"@fields": {
"text": ".//span[@class='text']/text()",
"author": ".//small[@class='author']/text()"
}
}
],
"@pagination": {
"@xpath": "//li[@class='next']/a",
"@limit": 3
}
}
๐ฌ Action System (NEW)
Handle dynamic, JavaScript-heavy websites with browser actions executed before data extraction:
JavaScript Site with Actions
{
"@url": "https://quotes.toscrape.com/js/",
"@actions": [
{
"@type": "wait",
"@until": "element",
"@selector": ".quote",
"@timeout": 10000
},
{
"@type": "scroll",
"@direction": "down",
"@pixels": 500
},
{
"@type": "wait",
"@until": "timeout",
"@timeout": 2000
}
],
"@steps": [
{
"@xpath": "//div[@class='quote']",
"@fields": {
"text": ".//span[@class='text']/text()",
"author": ".//small[@class='author']/text()"
}
}
]
}
Form Interaction
Fill forms and submit them:
{
"@url": "https://example-search.com",
"@actions": [
{
"@type": "fill",
"@selector": "input[name='search']",
"@value": "data extraction"
},
{
"@type": "click",
"@selector": "button[type='submit']"
},
{
"@type": "wait",
"@until": "element",
"@selector": ".search-results",
"@timeout": 10000
}
],
"@steps": [
{
"@xpath": "//div[@class='result']",
"@fields": {
"title": ".//h3/text()",
"url": ".//a/@href"
}
}
]
}
Supported Action Types
| Action | Purpose | Example |
|---|---|---|
| click | Click buttons, links | {"@type": "click", "@selector": "#load-more"} |
| scroll | Scroll page or elements | {"@type": "scroll", "@direction": "down", "@pixels": 500} |
| wait | Wait for conditions | {"@type": "wait", "@until": "element", "@selector": ".loaded"} |
| fill | Fill form fields | {"@type": "fill", "@selector": "input", "@value": "text"} |
| hover | Hover over elements | {"@type": "hover", "@selector": ".dropdown-menu"} |
๐ง Conditional Logic (NEW)
Extract different data based on page conditions with smart branching logic:
Premium vs Free Content Detection
{
"@url": "https://news-site.com/article/123",
"@steps": [
{
"@if": {"@exists": "#premium-content"},
"@then": [
{
"@xpath": "//div[@class='premium-article']",
"@fields": {
"title": ".//h1/text()",
"full_content": ".//div[@class='content']/text()",
"premium_features": ".//div[@class='extras']/text()"
}
}
],
"@else": [
{
"@xpath": "//div[@class='free-article']",
"@fields": {
"title": ".//h1/text()",
"preview": ".//div[@class='preview']/text()",
"paywall_message": ".//div[@class='paywall']/text()"
}
}
]
}
]
}
Authentication State Detection
{
"@url": "https://forum.example.com",
"@steps": [
{
"@if": {"@exists": ".user-menu"},
"@then": [
{
"@xpath": "//div[@class='authenticated-content']",
"@fields": {
"username": ".//span[@class='username']/text()",
"private_messages": ".//div[@class='messages']/text()",
"user_settings": ".//a[@class='settings']/@href"
}
}
],
"@else": [
{
"@xpath": "//div[@class='guest-content']",
"@fields": {
"login_prompt": ".//div[@class='login-required']/text()",
"signup_link": ".//a[@class='signup']/@href"
}
}
]
}
]
}
Search Results with Fallback
{
"@url": "https://search-engine.com/search?q=query",
"@steps": [
{
"@if": {"@min-count": 1, "@selector": ".search-result"},
"@then": [
{
"@xpath": "//div[@class='search-result']",
"@fields": {
"title": ".//h3/text()",
"url": ".//a/@href",
"snippet": ".//p[@class='description']/text()"
}
}
],
"@else": [
{
"@xpath": "//div[@class='no-results']",
"@fields": {
"message": ".//text()",
"suggestions": ".//div[@class='suggestions']//a/text()"
}
}
]
}
]
}
Supported Condition Types
| Condition | Purpose | Example |
|---|---|---|
| @exists | Element exists check | {"@exists": "#premium-section"} |
| @not-exists | Element absence check | {"@not-exists": ".advertisement"} |
| @contains | Text content check | {"@contains": "Premium Content"} |
| @count | Exact element count | {"@count": 3, "@selector": ".item"} |
| @min-count | Minimum count check | {"@min-count": 1, "@selector": ".result"} |
| @max-count | Maximum count check | {"@max-count": 10, "@selector": ".item"} |
๐ Query Keywords Reference
Core Keywords
| Keyword | Required | Description | Example |
|---|---|---|---|
@url |
โ | Target URL to scrape | "@url": "https://example.com" |
@steps |
โ | Extraction steps | "@steps": [...] |
@xpath |
โ | XPath selector for elements | "@xpath": "//div[@class='item']" |
@fields |
โ | Field definitions | "@fields": {"title": ".//h2/text()"} |
Optional Keywords
| Keyword | Description | Example |
|---|---|---|
@name |
Name for data group | "@name": "products" |
@actions |
Browser actions (v0.6+) | "@actions": [...] |
@pagination |
Pagination config | "@pagination": {"@xpath": "//a[@class='next']"} |
@limit |
Page limit | "@limit": 5 |
@follow |
Follow links | "@follow": {"@xpath": ".//a/@href"} |
Action Keywords (v0.6+)
| Keyword | Required | Description | Example |
|---|---|---|---|
@type |
โ | Action type | "@type": "click" |
@selector |
โ | CSS selector | "@selector": "#button" |
@xpath |
โ | XPath selector | "@xpath": "//button[@id='btn']" |
@until |
โ | Wait condition | "@until": "element" |
@timeout |
โ | Timeout (ms) | "@timeout": 5000 |
@direction |
โ | Scroll direction | "@direction": "down" |
@pixels |
โ | Scroll distance | "@pixels": 500 |
@value |
โ | Form field value | "@value": "search term" |
Conditional Keywords (v0.7+)
| Keyword | Required | Description | Example |
|---|---|---|---|
@if |
โ | Condition to evaluate | "@if": {"@exists": "#premium"} |
@then |
โ | Steps if condition true | "@then": [...] |
@else |
โ | Steps if condition false | "@else": [...] |
@exists |
โ | Element exists check | "@exists": "#element-id" |
@not-exists |
โ | Element absence check | "@not-exists": ".popup" |
@contains |
โ | Text content check | "@contains": "Premium Content" |
@count |
โ | Exact element count | "@count": 3 |
@min-count |
โ | Minimum count check | "@min-count": 1 |
@max-count |
โ | Maximum count check | "@max-count": 10 |
๐ฅ๏ธ CLI Reference
dr-web-engine [OPTIONS]
Required Arguments
-q, --query: Path to query file (JSON5/YAML)-o, --output: Output file path
Optional Arguments
| Flag | Description | Default |
|---|---|---|
-f, --format |
Query format (json5/yaml) |
json5 |
-l, --log-level |
Log level (error/warning/info/debug) |
error |
--log-file |
Path to log file | stdout |
--xvfb |
Run in virtual display (headless) | false |
Examples
# Basic extraction
dr-web-engine -q query.json5 -o results.json
# With debug logging
dr-web-engine -q query.json5 -o results.json -l debug
# Headless mode for servers
dr-web-engine -q query.json5 -o results.json --xvfb
# YAML query with log file
dr-web-engine -q query.yaml -o results.json -f yaml --log-file scraping.log
# Multiple runs with timestamp
dr-web-engine -q query.json5 -o "results_$(date +%Y%m%d_%H%M%S).json"
Automation Examples
# Cron job (daily at 2 AM)
0 2 * * * cd /path/to/queries && dr-web-engine -q daily.json5 -o "data/results_$(date +\%Y\%m\%d).json" --xvfb
# Process multiple queries
for query in queries/*.json5; do
output="results/$(basename "$query" .json5)_$(date +%Y%m%d).json"
dr-web-engine -q "$query" -o "$output" --xvfb -l info
done
๐ Real-World Examples
1. Hacker News with Dynamic Loading
{
"@url": "https://news.ycombinator.com",
"@actions": [
{"@type": "wait", "@until": "element", "@selector": ".athing", "@timeout": 10000},
{"@type": "scroll", "@direction": "down", "@pixels": 500}
],
"@steps": [
{
"@xpath": "//tr[@class='athing']",
"@fields": {
"title": ".//span[@class='titleline']/a/text()",
"url": ".//span[@class='titleline']/a/@href",
"rank": ".//span[@class='rank']/text()"
}
}
]
}
2. E-commerce Product Listings
{
"@url": "https://example-shop.com/products",
"@actions": [
{"@type": "wait", "@until": "network-idle", "@timeout": 10000}
],
"@steps": [
{
"@xpath": "//div[@class='product-card']",
"@fields": {
"name": ".//h3[@class='product-title']/text()",
"price": ".//span[@class='price']/text()",
"image": ".//img/@src",
"rating": ".//div[@class='rating']/@data-rating",
"reviews": "normalize-space(.//span[@class='review-count']/text())"
}
}
],
"@pagination": {
"@xpath": "//a[contains(@class, 'next-page')]",
"@limit": 5
}
}
3. Infinite Scroll Social Media
{
"@url": "https://social-media-site.com/feed",
"@actions": [
{"@type": "wait", "@until": "element", "@selector": ".post"},
{"@type": "scroll", "@direction": "down", "@pixels": 800},
{"@type": "wait", "@until": "timeout", "@timeout": 2000},
{"@type": "scroll", "@direction": "down", "@pixels": 800},
{"@type": "wait", "@until": "network-idle", "@timeout": 10000}
],
"@steps": [
{
"@xpath": "//article[@class='post']",
"@fields": {
"content": ".//p[@class='post-text']/text()",
"author": ".//span[@class='author']/text()",
"timestamp": ".//time/@datetime",
"likes": ".//span[@class='like-count']/text()",
"comments": "count(.//div[@class='comment'])"
}
}
]
}
4. Multi-Step Form Interaction
{
"@url": "https://job-board.com/search",
"@actions": [
{"@type": "fill", "@selector": "input[name='keywords']", "@value": "Python Developer"},
{"@type": "fill", "@selector": "input[name='location']", "@value": "New York"},
{"@type": "click", "@selector": "select[name='experience']"},
{"@type": "click", "@xpath": "//option[text()='3-5 years']"},
{"@type": "click", "@selector": "button[type='submit']"},
{"@type": "wait", "@until": "element", "@selector": ".job-listing", "@timeout": 15000}
],
"@steps": [
{
"@xpath": "//div[@class='job-listing']",
"@fields": {
"title": ".//h3/a/text()",
"company": ".//span[@class='company']/text()",
"location": ".//span[@class='location']/text()",
"salary": ".//span[@class='salary']/text()",
"url": ".//h3/a/@href"
}
}
]
}
๐งช Testing
DR Web Engine has comprehensive test coverage:
# Run all tests
python -m pytest engine/tests/
# Run specific test categories
python -m pytest engine/tests/unit/ # Unit tests
python -m pytest engine/tests/integration/ # Integration tests
python -m pytest engine/tests/e2e/ # End-to-end tests
# Run with coverage
python -m pytest engine/tests/ --cov=engine/web_engine --cov-report=html
Test Results
- 70 tests passed, 4 skipped
- Unit Tests: 48 tests (action models, handlers, core functionality)
- Integration Tests: 6 tests (engine integration, query execution)
- E2E Tests: 6 tests (real-world scenarios - 2 passing, 4 skipped for CI)
Test Categories
- โ Action Models: Validation, error handling, type safety
- โ Action Handlers: Click, scroll, wait, fill, hover functionality
- โ Action Processor: Execution pipeline, error handling
- โ Engine Integration: Query processing, pagination, browser management
- โ Parser Support: JSON5/YAML query parsing
- โ XPath Extraction: Field extraction, data transformation
๐ Documentation
Comprehensive Guides
- Getting Started Guide: Complete tutorial with 20+ examples
- Development Roadmap: Future features and improvements
- API Reference: Blog series with advanced patterns
Quick References
- Query Keywords: Complete keyword reference
- Action System: Browser interaction examples
- CLI Usage: Command-line options and automation
- Real Examples: Production-ready query patterns
๐ค Contributing
We welcome contributions! Here's how to get started:
Development Setup
# Clone and setup
git clone https://github.com/starlitlog/dr-web-engine.git
cd dr-web-engine
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
# Install Playwright browsers
playwright install
# Run tests
python -m pytest engine/tests/
Contribution Areas
- ๐ Bug Fixes: Fix issues and improve reliability
- โจ New Actions: Add new browser interaction types
- ๐ Documentation: Improve guides and examples
- ๐งช Testing: Add test coverage and scenarios
- ๐ Performance: Optimize extraction speed
- ๐ง CLI: Enhance command-line features
Submitting Changes
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Commit with clear messages
- Push and create a Pull Request
๐ License
This project is licensed under the MIT License. See LICENSE for details.
๐ Support
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: For private inquiries
- ๐ Documentation: Getting Started Guide
๐ Citation
If you use DR Web Engine in research, please cite our paper:
@misc{prifti2025drwebmodernquerybased,
title = {Dr Web: a modern, query-based web data retrieval engine},
author = {Ylli Prifti and Alessandro Provetti and Pasquale de Meo},
year = {2025},
eprint = {2504.05311},
archivePrefix = {arXiv},
primaryClass = {cs.DB},
url = {https://arxiv.org/abs/2504.05311},
}
๐ Read the Paper on arXiv โ
Made with โค๏ธ by the DR Web Engine Team
โญ Star on GitHub โข ๐ฆ Install from PyPI โข ๐ Read the Docs โข ๐บ๏ธ View Roadmap
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 dr_web_engine-0.7.0.tar.gz.
File metadata
- Download URL: dr_web_engine-0.7.0.tar.gz
- Upload date:
- Size: 70.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5bbd964450c2bab863a7200e59f50011ece29ccf75bfa0edfd7625e0e12280e
|
|
| MD5 |
995f05c71e31957e176c01b5b8be6959
|
|
| BLAKE2b-256 |
4a928a1d5284244441f5330f375739a2985495fcc31c1eb10bee1e40cb720d29
|
File details
Details for the file dr_web_engine-0.7.0-py3-none-any.whl.
File metadata
- Download URL: dr_web_engine-0.7.0-py3-none-any.whl
- Upload date:
- Size: 63.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58ec4b86b2b8dbb100e5702c9784d9810cd4daed0cf0fd5e630ce669b3da5303
|
|
| MD5 |
1b6ba9e2a4604a2272144c8af0a7359a
|
|
| BLAKE2b-256 |
6436ebd0e01b1163a70b311448c5f77b44f01d2e2af3092fc810057c1ef67fa0
|