#!/usr/bin/env python3
"""DMark: periksa apa yang disajikan saat URL memakai parameter (halaman menyusut 714KB → 165KB)."""
import re, urllib.request

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36"}


def ambil(u):
    r = urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=90)
    return r.status, r.read().decode("utf-8", "replace"), dict(r.headers)


for u in ("https://www.dmark.id/", "https://www.dmark.id/?v=99887"):
    st, h, head = ambil(u)
    t = re.search(r"<title[^>]*>(.*?)</title>", h, re.S)
    print(f"\n=== {u} ===")
    print(f"   status {st} | {len(h):,} byte | {head.get('content-type')}")
    print(f"   judul: {t.group(1)[:80] if t else '-'}")
    print(f"   jumlah <h1-6>: {len(re.findall('<h[1-6]', h, re.I))} | blok spectra: {len(re.findall('spectra', h, re.I))}")
    print(f"   ada 'Creative &': {'Creative' in h} | ada 'Demand Generation': {'Demand Generation' in h}")
    print(f"   ada skrip UAG/spectra: {len(re.findall(r'ultimate-addons|uag', h, re.I))}")
    # ambil 3 judul pertama yang terlihat
    print(f"   cuplikan isi: {re.sub(chr(10), ' ', re.sub(r'<[^>]+>', ' ', h[:1200]))[:260]}")
    print(f"   header penting: cache-control={head.get('cache-control')} | x-powered-by={head.get('x-powered-by')}")
