Skip to main content

A simple Python package for managing Selenium Chrome drivers in headless mode.

Project description

PyPI version License: MIT

headless-driver

A simple Python package for managing Selenium Chrome drivers in headless mode.

Features

  • Headless Chrome driver management
  • Temporary user data directory
  • Custom window size and user agent
  • Easy cleanup and context manager support
  • Remote and local driver 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)

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

Running Tests

python -m unittest discover tests

License

MIT

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.1.tar.gz (5.2 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.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: headless_driver-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • 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.1.tar.gz
Algorithm Hash digest
SHA256 df5a6e6c63a73d4551b582c6d3256e95c419efbbaf4c0fa7b8ee3aa0d7f4c91f
MD5 fbe49ebafa22c54b63fd75a00e31cb87
BLAKE2b-256 8b22f37179b69897c79333ac465395343c211d3a101cab6df2491a63ac91b5eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for headless_driver-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb0ad10ccc6816bc26141b1159190783cd04a39fe9858bd7c5bc8d53741c5381
MD5 4a8fa81bdc8631d5e4453d7d2b2b2bd1
BLAKE2b-256 11314fb304116cb773c83b24062c8e9f9b548732f1703e36556284293fc90afd

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