This project uses Puppeteer to automate the process of logging into a telecom service website and extracting data usage information.
- Automatically navigates to the login page
- Fills in the phone number (removed for privacy)
- Clicks the login button with a delay before clicking to ensure proper page state
- Waits for the information page to load
- Extracts package information including:
- Package name
- Used data amount
- Remaining data amount
- Total package data
- Includes retry mechanisms for robust operation
The script handles:
- Dynamic content loading with proper waits
- Complex selectors for uni-app framework elements
- Data extraction from specific DOM elements
- Retry mechanisms with configurable attempts and delays
- 50ms delay after filling the phone number before clicking login to allow UI updates
- Proper error handling and cleanup
Run the script with:
node project_files/extract_usage.jsThe script outputs package information in a structured format:
=== PACKAGE INFORMATION ===
Package Name: 1G流量年卡套餐
Used Data: 17.26MB
Remaining Data: 0.98GB
Total Package: 1.00GB
=========================
- puppeteer (for browser automation)
- Chromium (installed separately on the system at
/usr/sbin/chromium)
The script implements retry logic for key operations:
- Filling Phone Number: Up to 3 attempts with 2-second delays
- Clicking Login Button: Up to 3 attempts with 2-second delays
- Loading Information Page: Up to 3 attempts with 3-second delays
Each operation includes detailed logging to track attempts and success/failure status.