Capture a specific DOM element from any web page as an image (Playwright-first, Selenium fallback).
Project description
domishot
Capture just one DOM element from any web page and save it as an image.
- 🧠 Headless browser rendering (JS/CSS supported)
- 🎯 Element-only screenshots via CSS selector
- 🍪 Auto-accepts common cookie banners (best effort)
- 🖼️ Hi-DPI output (Playwright
device_scale_factor) - 🔧 Use it from the CLI or Python API
- 🔌 Choose your engine: Playwright (recommended) or Selenium
Table of Contents
Why domishot?
When you only need one widget/card/table from a web page—not the whole page—manual cropping and full-page screenshots are clunky and fragile. domishot:
- Loads the page like a browser (executes JS, applies CSS).
- Locates your target with a CSS selector.
- Saves only that element as a crisp PNG.
- Works great for dashboards, daily digests, bots, monitoring, and reports.
Quick Install
Pick one backend (you can install both).
Selenium (simpler start)
pip install "domishot[selenium]"
Playwright (recommended quality)
pip install "domishot[playwright]"
playwright install chromium
zsh users: always quote extras —
"domishot[selenium]"
Quick Start
CLI
domishot "https://www.omie.es/es/spot-hoy" "div.market-data-block.average" -o omie.png --backend selenium
Python
from domishot import capture, CaptureOptions
capture(
url="https://www.omie.es/es/spot-hoy",
selector="div.market-data-block.average",
out="omie.png",
opts=CaptureOptions(backend="auto", device_scale_factor=3) # sharper text
)
backend="auto"= use Playwright if installed, otherwise fall back to Selenium.
CLI Usage
domishot URL SELECTOR --out PATH
[--backend auto|playwright|selenium]
[--width 1400] [--height 1000] [--dpr 2]
[--locale es-ES] [--no-accept-cookies]
[--timeout 30000] [--extra-wait 400]
Arguments
URL– page to loadSELECTOR– CSS selector for the element (e.g.,#id,.card,#main > .widget)--out/-o– output PNG path (e.g.,snippet.png)--backend–auto(default),playwright, orselenium--width/--height– viewport size (px)--dpr– device pixel ratio (Playwright only)--locale– browser locale (defaultes-ES)--no-accept-cookies– disable cookie auto-accept--timeout– Playwright wait timeout in ms (default30000)--extra-wait– extra settle delay after scroll/render in ms (default400)
Python API
from domishot import capture, CaptureOptions
opts = CaptureOptions(
backend="auto", # or "playwright" / "selenium"
viewport=(1400, 1000),
device_scale_factor=2, # Playwright-only
wait_until="networkidle", # Playwright: "load"|"domcontentloaded"|"networkidle"
timeout_ms=30000,
locale="es-ES",
accept_cookies=True,
extra_wait_ms=400,
)
capture("https://example.com", "#main > .card", "card.png", opts)
Function reference
capture(url: str, selector: str, out: str, opts: Optional[CaptureOptions] = None) -> NoneCaptureOptionsfields:backend:"auto" | "playwright" | "selenium"viewport:(width, height)device_scale_factor: int (Playwright only; 2–3 for Hi-DPI)wait_until:"load" | "domcontentloaded" | "networkidle"(Playwright)timeout_ms: int (Playwright waits)locale: e.g.,"es-ES"accept_cookies: bool (auto-consent clickers)extra_wait_ms: int (post-render settle)
Examples
OMIE “spot-hoy”
# narrow card
domishot "https://www.omie.es/es/spot-hoy" "#block-prices-and-volumes" -o omie.png --backend selenium
# wider container
domishot "https://www.omie.es/es/spot-hoy" "div.market-data-block.average" -o omie.png
Hi-DPI with Playwright
domishot "https://example.com" ".kpi" -o kpi.png --backend playwright --dpr 3
Advanced Topics
Getting crisp text
- Prefer Playwright and set
--dpr 2or3. - If using Selenium, increase the viewport to capture at higher resolution.
Dynamic/Lazy content
- Increase
--extra-wait(e.g.,800–1500ms). - With Playwright,
wait_until="networkidle"helps in JS-heavy pages.
Cookie/consent banners
- domishot tries common patterns (
OneTrust, “Aceptar”, “Accept”…). - For custom banners, use
--no-accept-cookiesand handle manually in a fork.
Iframes / Shadow DOM
- If content lives inside an iframe or shadow root, you may need to extend the code:
- Playwright: target the frame via
page.frame(...)before selecting. - Selenium:
driver.switch_to.frame(...)then find the element.
- Playwright: target the frame via
Headless quirks
- Sites sometimes behave differently in headless mode.
- Try the other backend, increase
--extra-wait, or temporarily run non-headless in your fork for debugging.
Troubleshooting
“No supported backend available”
Install an extra:
pip install "domishot[selenium]"
# or
pip install "domishot[playwright]" && playwright install chromium
zsh error: no matches found: .[selenium]
Quote extras:
pip install -e ".[selenium]"
Build error: package directory 'src/domishot' does not exist
Ensure layout:
pyproject.toml
README.md
src/domishot/__init__.py
src/domishot/core.py
src/domishot/cli.py
Dependency conflicts (e.g., urllib3)
Use a dedicated virtual environment or upgrade the conflicting package.
Dynamic content never appears
Increase --extra-wait; ensure the selector matches what actually renders; consider Playwright.
Consent banner not dismissed
Pass --no-accept-cookies and extend selectors in core.py for your site.
Project Layout
domishot/
├─ pyproject.toml
├─ README.md
└─ src/
└─ domishot/
├─ __init__.py
├─ cli.py
└─ core.py
Versioning & Releases
- Follows semver-ish:
MAJOR.MINOR.PATCH - Do not reuse versions on PyPI/TestPyPI.
- Typical release flow:
- Bump
versioninpyproject.toml python -m buildtwine upload(TestPyPI first, then PyPI)
- Bump
Contributing
PRs welcome! A quick dev setup:
git clone https://github.com/<you-or-org>/domishot
cd domishot
pip install -e ".[playwright]" # or ".[selenium]"
playwright install chromium # if using Playwright
# smoke test:
domishot "https://www.omie.es/es/spot-hoy" "div.market-data-block.average" -o omie.png --backend playwright
License
MIT © Eric Moral
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 domishot-0.1.2.tar.gz.
File metadata
- Download URL: domishot-0.1.2.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cdd0424edb138a8ef0c575c11c206cc1e7ef0938aa9d132d29cb939085318e8
|
|
| MD5 |
3d74ac36b2075da41518e309f545cc36
|
|
| BLAKE2b-256 |
c2be981943d38a2c1fc3f80729e0c5d62d708ae29f31c74aa0271271099c13d4
|
File details
Details for the file domishot-0.1.2-py3-none-any.whl.
File metadata
- Download URL: domishot-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c9a9987c375fde4c967cdb9877f89f69038613ae7a4b716f189ba4495da164c
|
|
| MD5 |
b3a0f2fbac67a694f4a1a76247d7ce2f
|
|
| BLAKE2b-256 |
97e404373a2f5758380e7da6afe55e6d40681209be597bdc00568e6afe741d5f
|