Overview
This Mathspace Points Farmer farms a specific year 4 task available on every account with a different link for each, you just have to find it, and the script with do the rest.
How It Works
The script performs the following key actions:
- Browser Initialization: It starts a Chrome browser instance using Selenium WebDriver. It attempts to use a local ChromeDriver executable or falls back to
webdriver-manager to download the appropriate driver.
- Login: Automatically logs into Mathspace using credentials defined in the script.
- Problem Navigation: Monitors the browser's URL to detect when the user is on a "problem" page (identified by
state=problem in the URL).
- Question Extraction:
- Identifies and extracts text from main problem headers and subproblem sections.
- Employs specific logic to handle mathematical expressions rendered with MathQuill (looking for
mathquill-command-id attributes).
- Can search within iframes if questions are not found in the main document.
- Includes fallback methods if standard structures aren't detected.
- Text Cleaning: Processes the extracted text using regular expressions to remove irrelevant information, UI elements, promotional text, and normalize formatting.
- Calculation: Attempts to evaluate simple mathematical expressions (e.g.,
2 * 0, 7 / 1) from the cleaned question text.
- Answer Input: If a calculation is successful, the script tries to locate the answer input field on the page and types in the calculated result.
- Progression: Looks for and clicks "Continue Practicing" buttons to move to new sets of problems.
- Logging: Provides detailed console output about its operations, errors, and extracted content.
Key Features
- Automated login to Mathspace.
- Dynamic detection and processing of problem pages.
- Advanced question extraction, including MathQuill support and iframe handling.
- Robust text cleaning to isolate mathematical problems.
- Basic arithmetic calculation (currently focused on simple operations).
- Automated input of calculated answers.
- Handles common navigation elements like "Continue Practicing".
- Fallback mechanisms for WebDriver setup and question extraction.
Requirements & Setup
- Python 3.x: Ensure Python is installed on your system.
- Libraries: Install necessary Python packages by running:
pip install selenium webdriver-manager
- Google Chrome: The script is designed for Google Chrome.
- ChromeDriver:
- The script attempts to use a hardcoded path for
chromedriver.exe. You MUST update this path in app.py if you want to use a specific local version:
chromedriver_path = r"YOUR_PATH_TO_CHROMEDRIVER.EXE"
- If the specified path is invalid or fails, it will attempt to use
webdriver-manager to automatically download and manage the correct ChromeDriver.
- Credentials: Update the default username and password in
app.py:
DEFAULT_CREDENTIALS = {"username": "YOUR_USERNAME", "password": "YOUR_PASSWORD"}
How to Run
- Open a terminal or command prompt.
- Navigate to the directory where
app.py is located.
- Run the script using:
python app.py
- Press
Ctrl+C in the terminal to stop the script.