#!/usr/bin/env python3
"""DMark: cari tag judul 'Creativity is Intelegence' di HTML live (dengan & tanpa penembus cache)."""
import re, time, urllib.request, urllib.error

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

for q in ("", "?nocache=%d" % int(time.time()), "?v=99887"):
    u = f"https://www.dmark.id/{q}"
    try:
        r = urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=90)
        h = r.read().decode("utf-8", "replace")
        pos = h.find("Creativity is Intelegence")
        potongan = h[max(0, pos - 260):pos + 60] if pos > 0 else "(teks tidak ditemukan)"
        tag = re.findall(r"<h([1-6])[^>]*>(?=[^<]*Creativity is Intelegence)", h)
        print(f"\nq='{q or '(kosong)'}' | status {r.status} | panjang {len(h):,}")
        print(f"   tag judul kutipan: {['h'+t for t in tag] or '?'}")
        print(f"   cuplikan: {re.sub(chr(10), ' ', potongan)[-300:]}")
        print(f"   cf-cache-status: {r.headers.get('cf-cache-status')} | x-cache: {r.headers.get('x-cache')} | age: {r.headers.get('age')}")
    except Exception as e:
        print(f"q='{q}': gagal {str(e)[:80]}")
