This script automates the process of logging into the Moodle LMS (Moodle-based) and downloading all available course materials (PDFs, PPTs, etc.) from your enrolled courses.



Place scraper.py
and this README.md
in a folder of your choice.
Create a virtual environment (optional but recommended):
python -m venv venv
venv\Scripts\activate # On Windows
# or
source venv/bin/activate # On Linux/Mac
Install required packages:
pip install -r requirements.txt
Or install manually:
pip install requests beautifulsoup4 python-dotenv tqdm
Create a .env
file in the same directory as scraper.py
with the following content:
MYDY_USERNAME="your_lms_email@dypatil.edu"
MYDY_PASSWORD="your_lms_password"
Important: Do not use USERNAME
as the variable name on Windows - it's reserved by the system!
python scraper.py
The script will:
- Log you into the LMS
- Fetch your available courses
- Display an interactive menu to select courses
- Download all materials from selected courses with progress tracking
The script handles Moodle's two-step login:
- Submits username to get redirected to Moodle login
- Submits password to complete authentication
- Maintains session for subsequent requests
- Scans dashboard for enrolled courses
- Includes both current and previous semester courses
- Displays courses sorted by course ID (newest first)
The scraper identifies downloadable content from various Moodle activity types:
- Resource modules: Direct file downloads
- FlexPaper modules: Extracts PDF URLs from JavaScript
- Presentation modules: PowerPoint and other presentation files
- Object/Iframe content: Files embedded in various formats
- Creates separate folders for each course
- Uses sanitized course names for folder creation
- Preserves original filenames with proper URL decoding
Select course to download (1-X): [number for "Download ALL courses"]
Select course to download (1-X): [specific course number]
- "Login failed!": Double-check your
.env
file credentials - Username shows as Windows username: You're using
USERNAME
instead ofMYDY_USERNAME
- Timeout errors: The server might be slow; try running again
- No files downloaded: Course might have no downloadable content or you might not be enrolled
- Some activities failed: Normal - not all activities contain downloadable files
- Connection errors: Check your internet connection and try again
- Duplicate files: The script automatically skips existing files of the same size
- Invalid filenames: Script automatically sanitizes folder names for your OS
- Permission errors: Make sure you have write access to the script directory
- Credentials are stored in
.env
file and never hardcoded - Session cookies are temporary and only stored in memory
- Always add
.env
to your.gitignore
if using version control - The script respects rate limits to avoid overwhelming the server
- Python 3.10+
- Internet connection
- Valid LMS account
- Access to courses you want to download
MIT License. Use at your own risk.
This tool is for educational purposes only. Respect your institution's terms of service and use responsibly. Only download content you have legitimate access to.