[Open Source] A Python-based web automation tool for controlling browsers and sending and receiving data packets
![[Open Source] A Python-based web automation tool for controlling browsers and sending and receiving data packets](https://yy123.ink/api/img/1782588437373-1rldlh.jpg)
1. Project Overview
DrissionPage is a web automation tool based on Python.
It can control browsers, send and receive data packets, or combine both capabilities.
It combines the convenience of browser automation with the high efficiency of requests.
It is powerful and comes with countless user-friendly designs and convenient features.
Its syntax is simple and elegant, requires little code, and is beginner-friendly.
2. Open Source License
Released under the BSD-3-Clause open-source license
3. Screenshots
Official Website

Examples and Tips
Automatic Gitee Login
This example demonstrates how to automatically log in to the Gitee website by controlling a browser.
✅️️ Webpage Analysis
URL: [https://gitee.com/login](https://gitee.com/login)

Press F12 to inspect the code. You can see that both input fields can be located using their id attributes, as shown below.

✅️️ Implementation Approach
Locating elements with id attributes is very simple. Simply use the id attributes to locate both input fields.
The login button does not have an id attribute, but you can observe that it is the first element with a value attribute of 'Log In'. Using Chinese text to locate elements can also improve code readability.
Since we are using a browser for login, ChromiumPage is used here to control the browser.
✅️️ Example Code
from DrissionPage import ChromiumPage
# Create a page object in d mode (the default mode)
page = ChromiumPage()
# Navigate to the login page
page.get('[https://gitee.com/login](https://gitee.com/login)')
# Locate the username field and enter the username
page.ele('#user_login').input('Your username')
# Locate the password field and enter the password
page.ele('#user_password').input('Your password')
# Click the login button
page.ele('@value=Log In').click()
✅️️ Result
Successfully logged in.

4. Feature Overview
✨️ Overview
A Python-based web automation tool. It can control browsers and send and receive data packets. It combines the convenience of browser automation with the high efficiency of requests. It is powerful, with countless built-in user-friendly designs and convenient features. Its syntax is simple and elegant, requiring very little code.
Background
When using requests for data collection on websites that require login, you need to analyze network packets and JS source code, construct complex requests, and often deal with anti-scraping techniques such as CAPTCHAs, JS obfuscation, and signature parameters. This requires considerable expertise and results in low development efficiency. Using a browser can largely avoid these obstacles, but browser execution is relatively slow.
Therefore, the original design goal of this library was to combine both approaches, achieving both 'fast development' and 'fast execution'. It allows you to switch between the corresponding modes as needed and provides a user-friendly way to work, improving both development and runtime efficiency.
In addition to combining these two approaches, this library encapsulates commonly used features on a per-webpage basis, providing simple operations and statements. This allows users to focus on implementing functionality without worrying about implementation details. Powerful features can be implemented in simple ways, making code more elegant.
Earlier versions were implemented by re-encapsulating selenium. Starting with version 3.0, the author rebuilt the underlying architecture from scratch, eliminating the dependency on selenium, enhancing functionality, and improving execution efficiency.
Philosophy
Simple! Easy to use! Convenient!
☀️ Features and Highlights
The author has accumulated extensive practical experience over time, overcome countless challenges, and incorporated all these lessons into this library.
Powerful Self-Developed Core
This library uses a fully self-developed core and includes numerous practical features. It integrates and optimizes commonly used functionality. Compared with selenium, it offers the following advantages:
- No webdriver fingerprints, making it harder for websites to detect
- No need to download different drivers for different browser versions
- Faster execution
- Can locate elements across <iframe> without switching in and out
- Treats <iframe> as an ordinary element. Once retrieved, elements inside it can be located directly, making the logic clearer
- Can operate multiple browser tabs simultaneously, even when they are inactive, without switching between them
- Can directly read images from the browser cache and save them without using GUI clicks to select Save As
- Can capture screenshots of entire webpages, including content outside the viewport (supported by browser versions 90 and above)
- Can handle shadow-root elements that are not in the open state
Highlighted Features
In addition to the advantages above, this library includes countless user-friendly designs.
- Extremely simple syntax. Integrates numerous commonly used features, making code more elegant
- Easier element location with more powerful and stable functionality
- Built-in waiting and automatic retry mechanisms everywhere. Makes unstable networks easier to handle, improves program stability, and simplifies development
- Provides powerful download tools. Enjoy fast and reliable downloading even when operating a browser
- Allows repeated use of already-open browsers. No need to restart the browser from scratch every time you run the program, making debugging much more convenient
- Uses ini files to save commonly used configurations and loads them automatically, providing convenient settings without complicated configuration options
- Uses lxml as the built-in parsing engine, improving parsing speed by several orders of magnitude
- Encapsulated using the POM pattern, ready for direct use in testing and easy to extend
- Highly integrated convenience features, with attention to detail in every aspect
- There are many more details that cannot all be listed here. Feel free to explore them in actual use :)
5. Tech Stack
Running environment
Supported Operating Systems: Windows, Linux, Mac
Python Version: 3.6 and above
Supported Browsers: Chromium-based browsers (such as Chrome and Edge)
Disclaimer
Do not use DrissionPage for any work that may violate laws or ethical standards. Please use DrissionPage responsibly, comply with robots.txt policies, and do not use it for any illegal purposes. By choosing to use DrissionPage, you agree to comply with this agreement. The author assumes no legal risks or liability for any losses resulting from your violation of this agreement. You shall bear all consequences.