A single Python script that wraps all Browserless REST API endpoints as command-line subcommands. No external dependencies beyond Python's standard library.
- Zero dependencies — uses only Python's built-in
urllib,json,argparse - 15 commands covering the full Browserless API surface
- Configurable via CLI flags or environment variables
- Binary-safe output — handles text and binary responses (images, PDFs)
- Pipe-friendly — defaults to stdout for shell scripting
# Set up authentication
export BROWSERLESS_URL=https://production-sfo.browserless.io
export BROWSERLESS_TOKEN=your-api-token
# Get the rendered HTML of a page
python3 browserless-cli.py content https://example.com
# Take a screenshot
python3 browserless-cli.py screenshot https://example.com -o page.png
# Generate a PDF
python3 browserless-cli.py pdf https://example.com -o page.pdf| Option | Environment Variable | Description |
|---|---|---|
--url URL, -u URL |
BROWSERLESS_URL |
Browserless server URL (default: https://production-sfo.browserless.io) |
--token TOKEN, -t TOKEN |
BROWSERLESS_TOKEN |
API authentication token |
--output FILE, -o FILE |
— | Write output to FILE instead of stdout (use - for stdout) |
Fetches a page and returns the fully rendered HTML after JavaScript execution.
python3 browserless-cli.py content https://example.com
python3 browserless-cli.py content https://example.com -o page.html --wait-until networkidle2Options:
--wait-until— Wait condition:domcontentloaded,load,networkidle0,networkidle2--delay— Additional milliseconds to wait after the wait condition--headers— Extra HTTP headers as a JSON object (e.g.--headers '{"Cookie":"foo=bar"}')--extra-args— Comma-separated extra Chrome CLI args
Extracts structured data from a page using CSS selectors. Returns a JSON array.
python3 browserless-cli.py scrape https://example.com \
--elements '[{"name":"title","selector":"h1","attribute":"text"}]' \
-o results.jsonOptions:
--elements(required) — JSON array of element descriptors:[ {"name": "title", "selector": "h1", "attribute": "text"}, {"name": "links", "selector": "a", "attribute": "href"} ]--wait-until— Wait condition before scraping
Intelligently detects page content and returns it in the best format.
python3 browserless-cli.py smart-scrape https://example.com --output-format markdown
python3 browserless-cli.py smart-scrape https://example.com --output-format json -o data.jsonOptions:
--output-format— Preferred format:json,html,text,markdown--wait-until— Wait condition
Captures screenshots in PNG format.
python3 browserless-cli.py screenshot https://example.com -o page.pngOptions:
--type— Image format:png(default),jpeg,webp--full-page— Capture the entire scrollable page--quality— JPEG/WebP quality (1–100)--width— Viewport width--height— Viewport height--delay— Additional ms to wait--clip— Clip rectangle as JSON:{"x":0,"y":0,"width":800,"height":600}
Converts a web page to PDF with full print options.
python3 browserless-cli.py pdf https://example.com -o page.pdf
python3 browserless-cli.py pdf https://example.com -o report.pdf \
--landscape --print-background --delay 2000Options:
--landscape— Landscape orientation--paper-width— Paper width in inches--paper-height— Paper height in inches--margin— Margins as JSON:{"top":10,"right":10,"bottom":10,"left":10}--display-header-footer— Display header and footer--header-template— HTML template for header--footer-template— HTML template for footer--print-background— Print background graphics and colors--scale— Page scale (0.1–2.0)--delay— Additional ms to wait
Renders a page and saves it as clean Markdown text. Uses the /content endpoint and performs local HTML-to-Markdown conversion.
python3 browserless-cli.py markdown https://example.com -o page.mdOptions:
--wait-until— Wait condition (same ascontent)--delay— Additional ms to wait--headers— Extra HTTP headers as JSON object
Searches the web and optionally scrapes result pages.
python3 browserless-cli.py search "Python tutorials" --scrape --scrape-options '{"output":"markdown"}' -o results.jsonOptions:
--sources— Comma-separated search sources (e.g.google,duckduckgo)--scrape— Also scrape result pages--scrape-options— Scrape options as JSON
Discovers all URLs on a site, optionally preferring the sitemap.
python3 browserless-cli.py map https://example.com
python3 browserless-cli.py map https://example.com --sitemap
python3 browserless-cli.py map https://example.com --search "/blog/"Options:
--search— Filter URLs by path pattern--include-subdomains— Include subdomain URLs--sitemap— Prefer sitemap.xml over crawling
Fetches a page and extracts all <a> links as a JSON array of {text, url} entries. Resolves relative URLs to absolute.
python3 browserless-cli.py links https://example.com
python3 browserless-cli.py links https://example.com -o links.jsonOptions:
--wait-until— Wait condition:domcontentloaded,load,networkidle0,networkidle2--delay— Additional milliseconds to wait after the wait condition--headers— Extra HTTP headers as a JSON object (e.g.--headers '{"Cookie":"foo=bar"}')
Executes custom JavaScript code in a browser context. Sends raw JavaScript in the request body.
# Inline code
python3 browserless-cli.py function --code "return document.title;"
# From file
python3 browserless-cli.py function --code-file extract.js
# With context object
python3 browserless-cli.py function --code "return page.url();" --context '{"foo":"bar"}'Options:
--code— JavaScript code (inline)--code-file— Path to a.jsfile--context— Context object to pass to the function (JSON)
Runs JavaScript that triggers a file download and captures the file. Sends raw JavaScript in the request body.
python3 browserless-cli.py download --code-file download.js
python3 browserless-cli.py download --code "window.location.href = '/file.pdf';"Options:
--code— JavaScript code (inline)--code-file— Path to a.jsfile--context— Context object (JSON)
Fetches a URL and streams the response in its native content type.
python3 browserless-cli.py export https://example.com -o page.html
python3 browserless-cli.py export https://example.com -o bundle.zip --include-resourcesOptions:
--include-resources— Bundle all resources (CSS, images, JS) into a ZIP--wait-until— Wait condition--delay— Additional ms to wait
Bypasses bot detection and CAPTCHAs to access protected pages.
python3 browserless-cli.py unblock https://example.com -o page.html --content --cookies
python3 browserless-cli.py unblock https://example.com --content --screenshotOptions:
--content— Include rendered HTML in the response--cookies— Include browser cookies in the response--screenshot— Include a screenshot in the response--browser-ws-endpoint— Custom browser WebSocket endpoint
Runs a Lighthouse performance audit.
python3 browserless-cli.py performance https://example.com
python3 browserless-cli.py performance https://example.com --categories accessibility,seo
python3 browserless-cli.py performance https://example.com --only-pwaOptions:
--categories— Comma-separated Lighthouse categories:performance,accessibility,best-practices,seo,pwa--config— Lighthouse config as JSON--only-categories— Return only category scores--only-pwa— Run only PWA audit
Crawls a site at a given depth and optionally scrapes each page.
python3 browserless-cli.py crawl https://example.com --depth 2 --scrape --max-pages 100Options:
--depth— Crawl depth (default:1)--scrape— Scrape each page during crawl--scrape-options— Scrape options as JSON--path-filter— Comma-separated path filters (e.g./blog/,/about/)--max-pages— Maximum pages to crawl--delay— Delay between requests in ms
export BROWSERLESS_URL=https://production-sfo.browserless.io
export BROWSERLESS_TOKEN=abc123xyzpython3 browserless-cli.py --url https://my-browserless.io --token mytoken content https://example.comCLI flags override environment variables, which override defaults.
| Setting | Default | Env Var | CLI Flag |
|---|---|---|---|
| URL | https://production-sfo.browserless.io |
BROWSERLESS_URL |
--url |
| Token | "" |
BROWSERLESS_TOKEN |
--token |
python3 browserless-cli.py scrape https://example.com/shop \
--elements '[
{"name":"name","selector":".product-name","attribute":"text"},
{"name":"price","selector":".price","attribute":"text"}
]' -o prices.jsonpython3 browserless-cli.py screenshot https://dashboard.example.com \
-o dashboard.pngpython3 browserless-cli.py markdown https://blog.example.com/post \
-o blog-post.md --wait-until networkidle2python3 browserless-cli.py performance https://example.com \
--categories performance,accessibility,seo -o audit.jsonpython3 browserless-cli.py links https://blog.example.com -o links.jsonpython3 browserless-cli.py search "best LLM frameworks 2026" \
--sources google \
--scrape \
--scrape-options '{"output":"markdown"}' \
-o search-results.mdThis CLI wraps the following Browserless endpoints:
| Command | API Endpoint | HTTP Method |
|---|---|---|
content |
/content |
POST |
scrape |
/scrape |
POST |
smart-scrape |
/smart-scrape |
POST |
screenshot |
/screenshot |
POST |
pdf |
/pdf |
POST |
markdown |
/content (with local HTML→MD conversion) |
POST |
search |
/search |
POST |
map |
/map |
POST |
function |
/function |
POST |
download |
/download |
POST |
export |
/export |
POST |
unblock |
/unblock |
POST |
performance |
/performance |
POST |
crawl |
/crawl |
POST |
links |
/content (with local link extraction) |
POST |
Full API documentation: https://www.browserless.io/docs/
- Python 3.8+ (uses
dict[str, ...]type hints and f-string debugging) - No pip packages required — pure standard library
MIT