Quickstart¶
Context Manager (recommended)¶
The safest and most convenient way to use CDriv:
from cdriv import CDriv
with CDriv() as driver:
driver.new_session()
driver.navigate("https://example.com")
html = driver.get_page_source()
print(driver.get_title())
The with statement guarantees the ChromeDriver starts and stops correctly,
even when exceptions occur.
Manual Management¶
For full control over the lifecycle:
from cdriv import CDriv
driver = CDriv()
driver.start()
driver.new_session()
driver.navigate("https://example.com")
# ... your code here ...
driver.close()
driver.stop()
Configuration¶
Custom Port¶
Custom Binary Paths¶
driver = CDriv(
chromedriver_path="/usr/bin/chromedriver",
chromium_path="/usr/bin/chromium-browser",
)
Typical Script Structure¶
- Create a
CDrivinstance - Start a session with
new_session() - Navigate to the target URL
- Interact with the page
- Extract required data
- Close the session