Last active
July 23, 2025 15:34
-
-
Save AB498/33d002e3902a6cbe685fd97589ec0f72 to your computer and use it in GitHub Desktop.
Scrape + Download Google Classroom Files [Script]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 📌 Paste in browser console on a loaded Classroom page like: https://classroom.google.com/u/1/c/xxxxx | |
| // Step 1: Scroll to bottom to load all content | |
| while (await new Promise(r => setTimeout(r, 1500, scrollTo(0, h = document.body.scrollHeight))) || h != document.body.scrollHeight); | |
| // Step 2: Get current authuser (from /u/1/ in URL) | |
| const authuser = location.pathname.match(/\/u\/(\d+)/)?.[1] || '0'; | |
| // Step 3: Extract unique file IDs | |
| const ids = [...new Set([...document.querySelectorAll('a[href*="drive.google.com/file/d/"]')] | |
| .map(a => a.href.match(/\/file\/d\/([^/?]+)/)?.[1]) | |
| .filter(Boolean))]; | |
| // Step 4: Display original and download links + filename | |
| const entries = ids.map((id, i) => { | |
| const fileView = `https://drive.google.com/file/d/${id}?authuser=${authuser}`; | |
| const fileDownload = `https://drive.google.com/uc?export=download&id=${id}&authuser=${authuser}`; | |
| const a = [...document.querySelectorAll(`a[href*="${id}"]`)][0]; | |
| const name = a?.getAttribute('aria-label')?.match(/Attachment:.*?:\s*(.*)$/)?.[1] | |
| || a?.textContent?.trim().match(/[\w\s.-]+\.(pptx|pdf|docx|xlsx|txt|zip)/i)?.[0] | |
| || 'NO NAME'; | |
| console.log(`${i + 1}. ${fileView} (view)`); | |
| console.log(` ${fileDownload} (download) — ${name}`); | |
| return fileDownload; | |
| }); | |
| // Step 5: Open all file download links in staggered tabs (1 per second) (they auto close) | |
| // Also Allow Popups from Site Settings If Blocked | |
| entries.forEach((url, i) => { | |
| setTimeout(() => window.open(url, '_blank'), i * 1000); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment