{"id":7193,"library":"drissionpage","title":"DrissionPage","description":"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.","status":"active","version":"4.1.1.2","language":"en","source_language":"en","source_url":"https://github.com/g1879/DrissionPage","tags":["web automation","web scraping","browser automation","headless browser","requests","chromium"],"install":[{"cmd":"pip install drissionpage","lang":"bash","label":"Basic Installation"},{"cmd":"pip install drissionpage[chromium]","lang":"bash","label":"With Chromium Driver (Recommended for Browser Mode)"}],"dependencies":[{"reason":"Required for browser automation features. The `[chromium]` extra handles driver management.","package":"Chromium-based browser","optional":true}],"imports":[{"note":"The primary browser control class, directly available from the top-level package since v4.x. Older documentation or examples might show nested imports.","wrong":"from drissionpage.dp import ChromiumPage","symbol":"ChromiumPage","correct":"from DrissionPage import ChromiumPage"},{"note":"Used for efficient request-only mode, introduced in v3.0 as a replacement for Selenium dependencies. `MixPage` was the predecessor for combined modes prior to v3.0.","wrong":"from DrissionPage import MixPage","symbol":"WebPage","correct":"from DrissionPage import WebPage"},{"note":"Used for efficient request-only mode, similar to WebPage, also directly available from the top-level package. Prefer WebPage for newer code.","wrong":"from DrissionPage.dp import SessionPage","symbol":"SessionPage","correct":"from DrissionPage import SessionPage"}],"quickstart":{"code":"from DrissionPage import ChromiumPage\n\n# Initialize a browser page (Chromium is default)\npage = ChromiumPage()\n\n# Navigate to a website\npage.get('https://www.example.com')\n\n# Print the title of the page\nprint(f\"Page Title: {page.title}\")\n\n# Find an element by CSS selector and get its text\nelement = page.ele('css:h1')\nif element:\n    print(f\"H1 Text: {element.text}\")\n\n# Close the browser\npage.quit()\n","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Version 3.0 introduced significant architectural changes, reducing reliance on Selenium and introducing the `WebPage` class. Code written for pre-3.0 `MixPage` or direct Selenium integration may break.","severity":"breaking","affected_versions":"<3.0"},{"fix":"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.","message":"When using DrissionPage in multi-threaded environments, direct use of `Browser` objects across threads can lead to `AttributeError: 'Browser' object has no attribute '_driver'` or other unexpected behavior due to non-thread-safe internal states.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Element not found errors (`DrissionPage.errors.ElementNotFoundError`) are common, especially with dynamic content or incorrect locators. This can be due to the page not loading completely, elements not being present yet, or incorrect CSS/XPath selectors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Occasional timeout errors during page loading or `get()` requests can occur, particularly with unstable networks or heavily guarded websites.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the official DrissionPage documentation on managing browser profiles and multiple tabs/windows. Each profile often requires its own `ChromiumOptions` and `ChromiumPage` instance.","message":"Opening multiple browser profiles simultaneously requires specific configuration and careful management, and may not behave as expected if not handled correctly.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure each thread initializes its own `ChromiumPage` instance. Browser objects are not thread-safe.","cause":"Attempting to use a `Browser` or `ChromiumPage` object across multiple threads without proper isolation.","error":"AttributeError: 'Browser' object has no attribute '_driver'"},{"fix":"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')`).","cause":"The specified element could not be found on the page within the default timeout. This often happens if the element is dynamic, not yet loaded, or the locator is incorrect.","error":"DrissionPage.errors.ElementNotFoundError: 没有找到元素。"},{"fix":"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.","cause":"The browser or a specific operation (like `page.get()` or an element interaction) exceeded its allotted time before completing, possibly due to slow network, heavy page content, or anti-bot measures.","error":"TimeoutError: timeout"}]}