DrissionPage is a Python-based web automation tool that efficiently combines browser control functionalities (similar to Playwright or Selenium) with high-performance data packet handling (akin to Requests). It provides a unified and user-friendly API for tasks like web scraping, automated testing, and general web interaction, allowing seamless transitions between full browser and headless HTTP modes. The library is actively maintained, currently at version 4.1.1.2, and aims for a balance of power, elegance, and ease of use, with a development cadence that includes frequent updates and feature enhancements.
pip install drissionpageVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `ChromiumPage` instance, navigate to a URL, extract the page title and an element's text, and then close the browser. It showcases the core browser automation capabilities.
Review the official documentation for v3.0+ and migrate to `WebPage` for request mode or `ChromiumPage` for browser mode. Familiarize yourself with the new element interaction APIs.
Each thread should create and manage its own independent `ChromiumPage` or `WebPage` instance to ensure thread safety. Do not share a single `Browser` or `ChromiumPage` object across multiple threads.
Utilize DrissionPage's built-in waiting mechanisms (e.g., `page.wait.ele_loaded()`, implicit/explicit waits) before attempting to interact with elements. Double-check your CSS selectors or XPath expressions for accuracy.
Increase the default timeout values using `page.set.timeouts()` or pass `timeout` arguments to specific methods like `page.get()`. Implement retry logic for network-dependent operations. Consider using a proxy if network stability is an issue.
Consult the official DrissionPage documentation on managing browser profiles and multiple tabs/windows. Each profile often requires its own `ChromiumOptions` and `ChromiumPage` instance.
Ensure each thread initializes its own `ChromiumPage` instance. Browser objects are not thread-safe.
Verify your locator (CSS, XPath, etc.) and add explicit waits for the element to appear or be interactable (e.g., `page.wait.ele_loaded('css:.my-element')`).Increase the timeout for the operation or the page object (e.g., `page.set.timeouts(page_load_timeout=30)`). Implement retry logic for unreliable operations.