📄 SKILL.md

← Vault

name: gdrive-shared-folder-exploration

description: Explore, map, and crawl Google Drive shared folders with nested year/month/client structure using Playwright browser automation


Google Drive Shared Folder Exploration

When to Use

When you need to explore, map, or crawl a Google Drive shared folder with nested year/month/client structure. Use when:

Critical Discovery: Folder ID Hierarchy

Google Drive shared folders use a flat folder ID system. Each subfolder has its own ID, not nested paths.

`

Root ID: 1zVhApvpFM937qxsvsz37WCcUD-7f2zUP (documentos clientes/)

├── 2023: 1nObuuq8AhcUo-O96UdhaTBbrjaRzI4lP

│ ├── 08/2023: [unique month folder ID]

│ ├── 09/2023: [unique month folder ID]

│ └── ...

├── 2024: 1CcabJC1HF1V-tVUlq9IjkpCLNYRMN_l5

│ ├── 01/2024: [unique month folder ID]

│ └── ...

├── 2025: 17-KPk4ttAvtmz2hCXarIiW4O0MPh4rGZ

└── 2026: 1rlhX77Rq5F40qctMFMP7k2AxD5-U3rSS

`

Each year folder has a fixed ID. Each month subfolder has its own ID that must be discovered by navigating into the year folder.

Working Browser Automation Code

`python

from playwright.sync_api import sync_playwright

import time

PROFILE = "/tmp/gdrive_profile"

with sync_playwright() as p:

browser = p.chromium.launch_persistent_context(

user_data_dir=PROFILE,

headless=True,

args=["--no-sandbox", "--disable-dev-shm-usage"],

)

page = browser.pages[0]

# Navigate to a folder

page.goto("https://drive.google.com/drive/folders/[FOLDER_ID]", timeout=30000)

page.wait_for_timeout(6000) # Wait for content to render

# Get visible text content

content = page.inner_text("body")

# Find subfolder divs by aria-label

divs = page.query_selector_all('div[aria-label]')

for div in divs:

label = div.get_attribute('aria-label')

if label and '2024' in label: # filter as needed

print(label)

browser.close()

`

How to Get Month Folder IDs

Problem: The year folder page lists months, but clicking/navigating is slow and error-prone.

Working approach — navigate to year, then double-click each month div:

`python

divs = page.query_selector_all('div[aria-label]')

for div in divs:

label = div.get_attribute('aria-label')

if label and '01/' in label and '2024' in label:

div.dblclick()

time.sleep(3000)

month_url = page.url # This is the month folder URL

page.go_back()

time.sleep(2000)

break

`

Alternative (faster for mapping): Use page.inner_text('body') to get the month list, then for each month:

1. Navigate to year folder

2. Find the month div by aria-label matching "01/2024 Pasta compartilhada"

3. Double-click to enter

4. Extract client names from inner_text

5. Go back

Client Name Extraction

From month folder content, filter out UI elements:

`python

skip = ['Pular', 'Atalhos', 'Feedback', 'Acessibilidade', 'Drive', 'Fazer login',

'Caminho', 'Baixar', 'Nome', 'Proprietário', 'Data', 'Tamanho', 'Classificado',

'Ver opções', 'Pastas', 'Arquivos', 'Compartilhado', 'Modificado', 'Tamanho do arquivo',

'Pasta compartilhada', 'Proprietário oculto']

clients = []

for line in lines:

if len(line) > 5 and len(line) < 100 and not any(s in line for s in skip):

if not any(m in line.lower() for m in ['jan', 'fev', 'mar', 'abr', 'mai', 'jun',

'jul', 'ago', 'set', 'out', 'nov', 'dez', '2023', '2024', '2025', '2026',

'proprietário oculto', 'compartilhado']):

if line not in clients:

clients.append(line)

`

Known Pitfalls

1. Security scan blocking regex with backslashes: Don't use re.findall with patterns containing \. or \d — the security scanner blocks them. Use string methods or simple string matching instead.

2. page.wait_for_timeout() beats wait_for_selector: For Google Drive, wait_for_timeout(5000-8000) is more reliable than waiting for specific selectors since the page uses lazy loading.

3. aria-label format: Month folders use format like "01/2024 Pasta compartilhada" — include the full label including "Pasta compartilhada" when matching.

4. Slow exploration: Each double-click + go_back takes ~5 seconds. For 35 months x N clients, budget 3-5 minutes minimum. Use sampling (e.g., explore 3 months per year) to estimate totals without full crawl.

5. Browser session expiry: If page.title() returns "Fazer login", the Google session has expired. Re-authenticate manually or use a fresh profile.

6. --disable-web-security causes issues: Don't use this flag as it may cause Google to reject the session.

File: /tmp/gdrive_profile

Browser profile for the Google Drive session. Profile is persistent — if session expires, re-login manually in the browser at that profile path.