#!/usr/bin/env python3
"""DMark: apakah halaman LAIN juga kosong saat cache dilewati? (memastikan bukan ulah suntingan saya)"""
import re, 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"}


def ambil(u):
    try:
        r = urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=90)
        return r.status, r.read().decode("utf-8", "replace")
    except urllib.error.HTTPError as e:
        return e.code, ""
    except Exception as e:
        return 0, str(e)[:70]


UJI = ["/contact/", "/about-us/", "/what-we-do/", "/artikel/",
       "/7-ide-konten-kreatif-untuk-marketing-bisnis-kecil/", "/"]
for p in UJI:
    for akhiran in ("", "?nowprocket=1"):
        u = "https://www.dmark.id" + p + akhiran
        st, h = ambil(u)
        jumlah_judul = len(re.findall(r"<h[1-6]", h))
        t = re.search(r"<title[^>]*>(.*?)</title>", h, re.S)
        judul = t.group(1)[:38] if t else "-"
        tanda = "KOSONG" if jumlah_judul == 0 else f"{jumlah_judul} judul"
        print(f"   {st} | {len(h):>7} byte | {tanda:<10} | {judul:<40} | {p}{akhiran}")
    print()
