#!/usr/bin/env python3
"""DMark: apa sebenarnya yang disajikan untuk URL berparameter? (identifikasi halaman)"""
import html, 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.read().decode("utf-8", "replace")


for u in ("https://www.dmark.id/?v=99887", "https://www.dmark.id/?p=2034", "https://www.dmark.id/home-2/"):
    h = ambil(u)
    bersih = re.sub(r"\s+", " ", re.sub(r"<script.*?</script>|<style.*?</style>", " ", h, flags=re.S | re.I))
    teks = html.unescape(re.sub(r"<[^>]+>", " ", bersih))
    t = re.search(r"<title[^>]*>(.*?)</title>", h, re.S)
    print(f"\n=== {u} ===")
    print(f"   {len(h):,} byte | judul: {t.group(1)[:70] if t else '-'}")
    print(f"   teks terlihat (400 char): {re.sub(chr(32)+'+', ' ', teks).strip()[:400]}")
    POLA_TAUTAN = r'href="https://www.dmark.id/([a-z0-9\-/]{0,30})'
    print(f"   tautan utama: {sorted(set(re.findall(POLA_TAUTAN, h)))[:8]}")
    print(f"   ada formulir: {len(re.findall('<form', h, re.I))} | ada teks 'Services': {'Services' in h}")
