# Ajan tarayıcısında (browser-harness) bir sitenin iç sayfalarını gezip # masaüstü 1440 + mobil 390 tam sayfa JPEG ve sayfalar.json üretir. # Kullanım: BASE/SEED/OUT/LIMIT satırlarını düzenle, sonra: # export BU_CDP_WS= # BU_NAME= browser-harness < site_crawl.py > crawl.log 2>&1 (background) import time, json, base64, os BASE = 'https://ornek.com' SEED = ['/'] OUT = os.path.expanduser('~/ornek-mock/arastirma/ekran') LIMIT = 30 os.makedirs(OUT, exist_ok=True) seen, queue, meta = set(), list(SEED), [] def vis(): w = cdp('Browser.getWindowForTarget') cdp('Browser.setWindowBounds', windowId=w['windowId'], bounds={'windowState': 'minimized'}); time.sleep(1) cdp('Browser.setWindowBounds', windowId=w['windowId'], bounds={'windowState': 'normal'}) cdp('Page.bringToFront'); cdp('Emulation.setFocusEmulationEnabled', enabled=True) def shot(name, w, h, mobile): cdp('Emulation.setDeviceMetricsOverride', width=w, height=h, deviceScaleFactor=1, mobile=mobile) time.sleep(2.5) H = js("Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)") or h H = min(int(H), 8000) cdp('Emulation.setDeviceMetricsOverride', width=w, height=H, deviceScaleFactor=1, mobile=mobile) time.sleep(1.5) for _ in range(3): try: d = cdp('Page.captureScreenshot', format='jpeg', quality=80, captureBeyondViewport=True) open(f'{OUT}/{name}.jpg', 'wb').write(base64.b64decode(d['data'])); break except Exception as e: print('shot fail', name, e); vis(); time.sleep(2) return H new_tab(BASE + '/'); vis(); time.sleep(6) while queue and len(seen) < LIMIT: p = queue.pop(0) if p in seen: continue seen.add(p) cdp('Emulation.setDeviceMetricsOverride', width=1440, height=900, deviceScaleFactor=1, mobile=False) goto_url(BASE + p); time.sleep(7) name = (p.strip('/').replace('/', '_') or 'anasayfa')[:60] info = js("""(()=>({title:document.title, url:location.href, h1:[...document.querySelectorAll('h1,h2')].map(e=>e.innerText.trim()).filter(Boolean).slice(0,12), text:document.body.innerText.slice(0,30000), // uzun rehber/başvuru sayfalarında bulgu doğrulamak için tam metin gerekir links:[...new Set([...document.querySelectorAll('a[href]')].map(a=>a.getAttribute('href')))], imgsNoAlt:[...document.querySelectorAll('img')].filter(i=>!i.alt).length, imgs:document.querySelectorAll('img').length, fonts:[...new Set([...document.querySelectorAll('h1,h2,h3,p,a,button')].slice(0,200).map(e=>getComputedStyle(e).fontFamily.split(',')[0]))], buttons:[...document.querySelectorAll('button,a.btn')].map(b=>b.innerText.trim()).filter(Boolean).slice(0,30)}))()""") info['h_masaustu'] = shot(f'{name}__masaustu', 1440, 900, False) info['h_mobil'] = shot(f'{name}__mobil', 390, 844, True) info['path'] = p meta.append(info) for l in info.get('links') or []: if l and l.startswith('/') and not l.startswith('//') and not l.endswith(('.pdf', '.png', '.ico', '.json')): l = l.split('#')[0].split('?')[0] or '/' if l not in seen and l not in queue: queue.append(l) json.dump(meta, open(os.path.join(OUT, '..', 'sayfalar.json'), 'w'), ensure_ascii=False, indent=1) print(p, info['h_masaustu'], info['h_mobil']) cdp('Emulation.clearDeviceMetricsOverride') print('TOPLAM', len(meta), 'kalan', queue[:20])