Skip to main content
headless-driver

headless-driver

Headless Chrome automation and a multi-engine search scraper for Python.
Proxy and stealth support, automatic driver installation, screenshots and PDF export, multi-driver management, and a colourful CLI.

PyPI version Python versions Downloads Package status License

Tests Selenium Chrome headless Platforms

Stars Forks Issues Last commit PRs welcome

Sponsor Buy me a coffee


Documentation · Quick start · CLI · Engines · PyPI · Issues


Features

  • Headless and windowed Chrome management, with temporary or persistent profiles
  • HTTP and SOCKS proxy support, plus optional stealth mode
  • Automatic ChromeDriver installation, and recovery when the installed driver does not match your Chrome
  • Screenshot and PDF export via Chrome DevTools
  • Download folder management
  • Multi-driver manager for many isolated browser instances
  • Search scraping across 8 engines, starting with DuckDuckGo's no-JavaScript endpoint and falling back automatically when one blocks you
  • Bounded page-load timeouts, so a stalled engine fails over instead of hanging
  • A headless-driver CLI with coloured output, --json for piping, and a doctor command that diagnoses your setup

Install

pip install headless-driver

Needs Python 3.9+ and an installed Chrome or Chromium. A matching ChromeDriver is downloaded automatically when required.

On Debian/Ubuntu you can install a system browser and driver with:

sudo apt update && sudo apt install -y chromium chromium-driver

Quick start

from headless import Headless

with Headless() as driver:
    driver.get("https://example.com")
    print(driver.title)

Search the web:

from headless import AdvancedSearchScraper

with AdvancedSearchScraper(max_results=5) as scraper:
    for item in scraper.search("python headless browser"):
        print(item["title"], item["url"])
    print("answered by", scraper.last_engine)

Screenshot and PDF:

from headless import ExtendedHeadless

hl = ExtendedHeadless(stealth=True)
driver = hl.get_driver()
driver.get("https://example.com")

hl.screenshot("example.png")
hl.save_pdf("example.pdf")
hl.quit()

Command line

headless-driver search "python headless browser" -n 5
headless-driver search "selenium stealth" --json | jq -r '.results[].url'
headless-driver engines                    # engine list and fallback order
headless-driver doctor                     # check chrome, driver, connectivity
headless-driver shot https://example.com -o page.png --window 1280x720
headless-driver pdf  https://example.com -o page.pdf

doctor is the quickest way to explain a failing run:

── browser ──────────────────────────────────────────────
 ✓ chrome              Google Chrome 151.0.7922.140
 ✓ chromedriver        ChromeDriver 148.0.7778.179
 ! version match       chrome 151 vs driver 148 - a matching driver will be downloaded
── connectivity ─────────────────────────────────────────
 ✓ html.duckduckgo.com  reachable
 ✓ www.bing.com         reachable
── smoke test ───────────────────────────────────────────
 ✓ launch and navigate  page title 'ok'

 13 passed, 1 warning  +++++++++++++~

Colour switches off automatically when output is not a terminal, so piping gives plain text. NO_COLOR=1 or --no-color disables it; FORCE_COLOR=1 forces it on. Diagnostics go to stderr, keeping --json on stdout clean. Exit status is 0 on success, 1 when nothing could be produced, 2 for a usage error.

See DOCS.md for every command and flag.

Search engines

Searching starts at DuckDuckGo's no-JavaScript endpoint, which returns server-rendered HTML and so is much faster than the JavaScript front end. If an engine serves a bot check, returns nothing, or stalls, the next one is tried:

duckduckgo → duckduckgo_lite → bing → mojeek
           → duckduckgo_js → startpage → google → yandex

search() returns [] only once every engine has been tried.

AdvancedSearchScraper(search_engine="bing")                # start elsewhere
AdvancedSearchScraper(fallback=False)                      # single engine
AdvancedSearchScraper(fallback_engines=["bing", "mojeek"])  # custom order
scraper.search("query", engine="bing")                     # force, one-off

Add your own engine with register_engine(). Full details, including the result dict and redirect handling, are in DOCS.md.

More

Support

If this project saves you time, you can support its development:

Sponsor Buy me a coffee

Starring the repository helps too.

License

MIT — see LICENSE.

Happy coding 🚀

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

headless_driver-0.2.2.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

headless_driver-0.2.2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file headless_driver-0.2.2.tar.gz.

File metadata

  • Download URL: headless_driver-0.2.2.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for headless_driver-0.2.2.tar.gz
Algorithm Hash digest
SHA256 653c45a056cbb192df5fcbdb5ef5c3c241c204ccc63e8bc662bd2cd8ce3b3df6
MD5 beed7aa0bc7fe5f7d18dbe7f60242a89
BLAKE2b-256 4dba96d9caf47d761886745b7bb2c0af2bae43052eb341277e402ccaf0814889

See more details on using hashes here.

File details

Details for the file headless_driver-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for headless_driver-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 688ca5ec81e817294c88514a641726f41f262f56e7488050d4c5f649082147c5
MD5 8529e7b01ecbbe28ed6c800b7f983c3e
BLAKE2b-256 2696d1a5e2a6d8eea0a929fa88e13781de481c632aad1f2cde87222df29d3efd

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page