web-capture (Rust)
A CLI and microservice to fetch URLs and render them as:
- HTML: Rendered page content
- Markdown: Converted from HTML
- PNG screenshot: Full page capture
This is the Rust implementation of web-capture, providing the same API as the JavaScript version.
Installation
From crates.io
From Source
Quick Start
CLI Usage
# Capture a URL as HTML (output to stdout)
# Capture as Markdown and save to file
# Take a screenshot
# Start as API server
# Start server on custom port
API Endpoints (Server Mode)
- HTML: GET /html?url=
- Markdown: GET /markdown?url=
- PNG screenshot: GET /image?url=
CLI Reference
Server Mode
Start the API server:
| Option | Short | Description | Default |
|---|---|---|---|
--serve |
-s |
Start as HTTP API server | - |
--port |
-p |
Port to listen on | 3000 (or PORT env) |
Capture Mode
Capture a URL directly:
| Option | Short | Description | Default |
|---|---|---|---|
--format |
-f |
Output format: html, markdown/md, image/png |
html |
--output |
-o |
Output file path | stdout (text) or auto-generated (images) |
Examples
# Capture HTML to stdout
# Capture Markdown to file
# Take screenshot
# Pipe HTML to another command
|
Docker
# Build and run
Library Usage
Add to your Cargo.toml:
[]
= "0.1"
Example
use ;
async
API Endpoints
HTML Endpoint
Returns the raw HTML content of the specified URL.
Parameters:
url(required): The URL to fetch
Markdown Endpoint
Converts the HTML content of the specified URL to Markdown format.
Image Endpoint
Returns a PNG screenshot of the specified URL.
Parameters:
url(required): The URL to capture
Configuration
Environment Variables
# Set port via environment variable
# Enable debug logging
Built With
- Axum - Web framework
- browser-commander - Browser automation
- html2md - HTML to Markdown conversion
- scraper - HTML parsing
- Tokio - Async runtime
License
Unlicense — This is free and unencumbered software released into the public domain. You are free to copy, modify, publish, use, compile, sell, or distribute this software for any purpose, commercial or non-commercial, and by any means. See https://unlicense.org for details.