Skip to main content

Lightweight Python library to manage Selenium Chrome WebDriver in headless mode with proxy, stealth, auto-driver installation, multi-driver management, download handling, and advanced search scraping utilities.

Project description

PyPI version License: MIT Python Versions Downloads

headless-driver

Lightweight Python pacakge to manage Selenium WebDriver in headless mode with proxy support, stealth tweaks, auto-driver installation, multi-driver management, download handling, and advanced search-scraping utilities

Features

  • Headless and non-headless Chrome management
  • Temporary or persistent user-data directories (profiles)
  • HTTP and SOCKS proxy support
  • Optional stealth mode (integrates with selenium-stealth when available)
  • Automatic ChromeDriver install (via webdriver-manager) as an optional dependency
  • Download folder management and automatic cleanup
  • Screenshot and PDF export via Chrome DevTools
  • Multi-driver manager to run many isolated browser instances
  • Advanced search scraper (DuckDuckGo default) with title, snippet, favicon, cached link, and batch search/export support

Installation

pip install headless-driver

Usage

from headless import Headless

hl = Headless()
driver = hl.get_driver()
driver.get("https://example.com")
print(driver.title)
hl.quit()

Or use as a context manager:

from headless import Headless

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

Search

from headless import SearchScraper, Headless

hl = Headless()
driver = hl.get_driver()

scraper = SearchScraper(driver=driver, max_results=5)

results = scraper.search("Nuhman PK github")
print(results)

Stealth

from headless import ExtendedHeadless

hl = ExtendedHeadless(stealth=True)

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

print(driver.title)

hl.quit()

Proxy

from headless import ExtendedHeadless

hl = ExtendedHeadless(proxy="socks5://127.0.0.1:9050")

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

print(driver.title)

hl.quit()

Take Screen / Export PDF

from headless import ExtendedHeadless

hl = ExtendedHeadless(download_dir="/tmp/hd_downloads")
d = hl.get_driver()

d.get("https://example.com")

hl.screenshot("/tmp/example.png")
hl.save_pdf("/tmp/example.pdf")

hl.quit()

Auto Install Driver

from headless import ExtendedHeadless

hl = ExtendedHeadless(auto_install=True)
d = hl.get_driver()

d.get("https://example.com")

hl.screenshot("/tmp/example.png")
hl.save_pdf("/tmp/example.pdf")

hl.quit()

Multi driver manager

from headless import MultiDriverManager

mgr = MultiDriverManager()
a = mgr.create("bot1", stealth=True, auto_install=True)
b = mgr.create("bot2", proxy="http://1.2.3.4:3128", download_dir="/tmp/d2", auto_install=True)
da = a.get_driver()
db = b.get_driver()
mgr.quit_all()

Advanced scraper

from headless import AdvancedSearchScraper

scr = AdvancedSearchScraper(headless_options={"headless": True}, max_results=5)

res = scr.search("python headless")

batch = scr.search_batch(["python headless", "selenium stealth"], max_workers=2)

scr.export("results.json")
scr.quit()

API Documentation

Headless class

Headless(
    user_data_dir: Optional[str] = None,
    window_size: Tuple[int, int] = (1920, 1080),
    user_agent: Optional[str] = None,
    headless: bool = True,
    chrome_driver_path: Optional[str] = '/opt/homebrew/bin/chromedriver',
    additional_args: Optional[List[str]] = None,
    remote_url: Optional[str] = None,
)
  • user_data_dir: Path for Chrome user data (temporary if not provided)
  • window_size: Browser window size (default: 1920x1080)
  • user_agent: Custom user agent string
  • headless: Run Chrome in headless mode (default: True)
  • chrome_driver_path: Path to chromedriver executable
  • additional_args: List of extra Chrome arguments
  • remote_url: Use remote Selenium server if provided

Methods

  • get_driver(): Returns a Selenium WebDriver instance
  • quit(): Quits the driver and cleans up user data

Install Driver on Linux

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

Happy coding 🚀

Project details


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.1.4.tar.gz (1.9 MB 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.1.4-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: headless_driver-0.1.4.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for headless_driver-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cfd5c0672c5ec4ef379c170e9754e44fb14645c67fd15b825c96aa4104a05760
MD5 d23999ce0d66aec7f96ed11262230316
BLAKE2b-256 8e746be2fca9dd3effa58b2f1be761120b5e257c27819e1ec88e62e064d493ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for headless_driver-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 95ad8a62671dcc2d6eb83c4f7e9e4f4c148efedf284889f892c8a5eb30667e07
MD5 fce80258692e999c37810867990b4642
BLAKE2b-256 21f0aac5cb334aaa0bb4faec443e9d6939717dcd08c74545b57cf615df7ef04c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page