A data retrieval engine based on Playwright.
Project description
DR Web Engine
DR Web Engine is an open-source data retrieval engine designed for extracting structured data from web pages using Playwright. It allows users to define queries in JSON5 or YAML format and execute them to retrieve data from websites. The project is highly extensible and can be used for web scraping, data extraction, and automation tasks.
Features
- Queryable Web: Define data extraction queries in JSON5 or YAML format.
- Playwright Integration: Leverages Playwright for reliable and efficient web automation.
- Extensible: Easily extend the engine by adding new parsers, extractors, or custom logic.
- Command-Line Interface (CLI): Run queries directly from the terminal.
- Docker Support: Use the engine in a containerized environment for easy deployment.
Installation
Option 1: Install from Source
- Clone the repository:
git clone https://github.com/starlitlog/dr-web-engine.git cd dr-web-engine
- Install dependencies:
pip install -r requirements.txt
- Install the project in editable mode:
pip install -e .
Option 2: Install via pip
The project is available on PyPI. You can install it directly via pip:
pip install dr-web-engine
Option 3: Run with Docker
- Build the Docker image:
docker build -t dr-web-engine .
- Run the container, mounting your local data directory:
docker run -v $(pwd)/data:/app/data dr-web-engine -q /app/data/query.json5 -o /app/data/output.json
Usage
Command Line Interface (CLI)
To execute queries using the CLI, run:
dr-web-engine -q engine/data/query.json5 -o engine/data/output.json
Available Parameters
-qor--query: Path to the query file (JSON5 or YAML format).-oor--output: Path to the output file where results will be saved.-for--format: Query format (json5oryaml). Default:json5.-lor--log-level: Set the logging level (error,warning,info,debug). Default:error.--log-file: Path to a log file. If not specified, logs are printed to stdout.
Extending the Project
Adding New Parsers
To add a custom parser:
- Create a new parser in the
web_engine/parsers/directory. - Implement a
parse()function that takes a file path and returns a parsed query. - Register the parser in
web_engine/parsers/__init__.pyusing theget_parser()function.
Example:
# web_engine/parsers/custom_parser.py
def parse(file_path):
# Custom parsing logic here
return parsed_query
Adding New Extractors
To add a new extractor:
- Create a new extractor in the
web_engine/extractors/directory. - Implement the extraction logic.
- Update the
execute_query()function inweb_engine/engine.pyto use the new extractor.
Adding New Query Types
To define a new query type:
- Create a new query model in
web_engine/models.py. - Modify the
ExtractionQueryclass to support the new query type. - Add the relevant parsing and extraction logic for the new query type.
Example Queries
JSON5 Query Example
{
"@url": "https://example.com",
"@steps": [
{
"@xpath": "//div[@class='item']",
"@name": "items",
"@fields": {
"title": ".//h2",
"description": ".//p"
}
}
],
"@pagination": {
"@xpath": "//a[@class='next']",
"@limit": 5
}
}
YAML Query Example
url: https://example.com
steps:
- xpath: //div[@class='item']
name: items
fields:
title: .//h2
description: .//p
pagination:
xpath: //a[@class='next']
limit: 5
Learn More
For additional details and use cases, check out the blog posts at:
Contributing
Contributions are welcome! To contribute, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
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.5.1.1.tar.gz.
File metadata
- Download URL: dr_web_engine-0.5.1.1.tar.gz
- Upload date:
- Size: 46.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b16a9885c653c98d7c356d0c1a478ec2e1076d644a0b1c712da0edd9cf60d4fe
|
|
| MD5 |
9771b2a7aa3b805a5d58dab6578db557
|
|
| BLAKE2b-256 |
0d98e7de951a8449b6f1a798c2411edb6145a0b1e1097d011a4338558a24fd69
|
File details
Details for the file dr_web_engine-0.5.1.1-py3-none-any.whl.
File metadata
- Download URL: dr_web_engine-0.5.1.1-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43c3e59bd1c7b1c63af24c66527a0b5fc0a7e2a9df0f68b940438112c046e944
|
|
| MD5 |
4f59c4bcbd2bb7ae4fc3dc7406b80fdb
|
|
| BLAKE2b-256 |
2588ce0a62c9b991db3cc1a5daa2ffa37e52aafafa73d23edf2d827250131db6
|