Skip to main content

contextmanager for managing `selenium` chrome sessions with caching.

Project description

chromesession

chromesession is a Python package that provides a convenient contextmanager for managing selenium chrome sessions.

In addition, a CachedSession is provided to directly cache the driver responses.

Installation

pip install chromesession

To use the chromesession.chrome contextmanager to use selenium, the chromedriver must be installed the system.

Alternatively, you can install the latest chromedriver as extra.

PyPI - eth-hash

pip install chromesession[driver]

Examples

Cache the specified URLs by fetching them via Selenium and saving the responses.

import logging

from chromesession import CachedSession, chrome


def caching(*urls: str) -> None:

    with CachedSession("caching.sqlite") as session:
        with chrome() as driver:
            for url in urls:
                if url in session:
                    logging.info(f"{url=} already cached.")
                    continue

                try:
                    driver.get(url)
                    session.save_driver(driver)
                except Exception as e:
                    logging.error(f"{url=} failed to cache: {e}", exc_info=True)
                else:
                    logging.info(f"{url=} from cache.")


if __name__ == "__main__":

    caching("https://example.com/", "https://example.com/")

Dependencies

PyPI - requests-cache PyPI - responses PyPI - selenium


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

chromesession-0.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

chromesession-0.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file chromesession-0.0.0.tar.gz.

File metadata

  • Download URL: chromesession-0.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.2 Windows/10

File hashes

Hashes for chromesession-0.0.0.tar.gz
Algorithm Hash digest
SHA256 4959f4b7d23bfb6e334d5cfb65a092673f339fa4857ae5a35104f6da4ae8f954
MD5 50fce54b75aadf8b3a12d5ee08bf417a
BLAKE2b-256 11a371fd01845d0f1b5c2bf654dbfd46905eda00cef1aa455a40c2ea48fab742

See more details on using hashes here.

File details

Details for the file chromesession-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: chromesession-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.2 Windows/10

File hashes

Hashes for chromesession-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a7d45630077fe92fe4f4816be49aa2d1873ac5d2ac7d99b06e3f87fb7fe1c5b
MD5 97b43e18bb051106a00c71088a303268
BLAKE2b-256 8f61437c5bed3fc572a09a05ba2f279ebf60ca292b32cd3205327b2530b94d64

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