Complete code
from DrissionPage import Chromium, ChromiumOptions, ChromiumPage # Create a browser option object (read from the ini file by default)co = ChromiumOptions() # Get the method, enter the browser address bar: se://version/# Note: 360 browser can only open one window at a time, so you need to close all windows first# Configure the path to the browser to connect toco.set_browser_path(r"C:\Users\Administrator\AppData\Roaming\360se6\Application\") # Set user data directoryco.use_system_user_path(r"c:\users\administrator\appdata\roaming\360se6\User Data\Default") # Create a ChromiumPage object using custom optionspage = ChromiumPage(co) print("✅ Browser startup successfully") # Visit the target page("") print("✅ Accessing the target page successfully") # Get page elementsele = ("css:#su") # Print elementsprint(ele)
introduction
In the field of web page automation, we often encounter scenarios such as needing to keep logged in and retain cookies. The solution to share today can perfectly solve this problem: use DrissionPage to directly call the user data of the local 360 browser to achieve seamless automation control.
Why use existing user data?
- No login: Directly use the logged-in account status
- Keep personalized settings: All bookmarks, plug-ins, and history records are there
- A more realistic user environment: Completely reuse your browser configuration
- Save time: No need to repeatedly configure the browser environment
Core code implementation
1. Import the necessary modules
from DrissionPage import Chromium, ChromiumOptions, ChromiumPage
2. Key configuration (key points!)
# Create a browser option objectco = ChromiumOptions() #Core Step 1: Set the local 360 browser pathco.set_browser_path(r"C:\Users\Administrator\AppData\Roaming\360se6\Application\") # Core Step 2: Specify the user data directory, which is the key to implementing reuseco.use_system_user_path(r"c:\users\administrator\appdata\roaming\360se6\User Data\Default")
3. Start the browser and use it
# Create a browser instance using configurationpage = ChromiumPage(co) print("✅ Browser startup successfully") # Visit the web page("") print("✅ Accessing the target page successfully")
Practical Tips
1. Get the browser path
- Enter in the 360 browser address bar:
se://version/
- You can see detailed browser information and paths
2. User data directory description
- Default location:
C:\Users\Username\AppData\Roaming\360se6\User Data\Default
- Including: cookies, bookmarks, history, plug-in configuration, etc.
3. Notes (Important)
- Please close all 360 browser windows before use
- 360 browser can only open one instance at a time
- It is recommended to back up user data directory regularly
Application scenarios
1. Automated testing
- Test using real user environment
- Quickly reproduce user reports issues
2. Data collection
- Directly use the logged-in account status
- Avoid account abnormalities caused by frequent login
3. Automated office
- Quickly process business systems that require login
- Keep multiple systems logged in
Program Advantages
- Completely reused: 100% restore the user's browser environment
- Simple configuration: Only two lines of core code are required
- Stable and reliable: Use the official browser kernel
- Easy to maintain: No additional configuration files are required
Frequently Asked Questions
1. Startup failed
# Checkpoint 1: Browser pathprint(co.get_browser_path()) # Checkpoint 2: User Data Directoryprint(co.get_user_data_path())
2. Permission issues
- Ensure read and write permissions to the user data directory
- Run Python programs as administrator
Extended application
1. Multi-user data management
# Switch different user data directoriesco.use_system_user_path(r"path/to/another/profile")
2. Automation scenario example
# Example: Automatically handle logged in("") # Direct access to QQ mailbox, no need to log inele = ("Selector for Write Button") ()
Summarize
By using DrissionPage with 360 browser user data, we can easily achieve:
- Completely reuse user environment
- Keep all websites logged in
- Realize automated operations
This solution greatly simplifies the automation process and improves efficiency, making it a very practical automation solution.
Follow-up suggestions
- Regularly backup user data
- Consider creating a dedicated automated test user data directory
- In actual projects, they can be encapsulated into configuration classes for easy management
The above is the detailed content of the perfect solution to control the 360 browser using DrissionPage. For more information about DrissionPage control the 360 browser, please follow my other related articles!