#!/usr/bin/env python3
"""DAS: verifikasi tombol AMBIL PROMO di halaman LIVE (warna, tautan, teks)."""
import re, time, urllib.request

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124 Safari/537.36"}
UJI = ["/bengkel-spesialis-nissan-surabaya/", "/bengkel-spesialis-matic-surabaya/",
       "/bengkel-spesialis-lexus-di-surabaya/", "/tips-memilih-ban-mobil-untuk-jalan-indonesia/",
       "/perawatan-rem-mobil-tanda-tanda-yang-terabaikan/"]

for u in UJI:
    try:
        h = urllib.request.urlopen(urllib.request.Request(f"https://dasindonesia.com{u}", headers=UA), timeout=90).read().decode("utf-8", "replace")
        tombol = re.findall(r'<a[^>]*>(?:(?!</a>).){0,80}?AMBIL PROMO(?:(?!</a>).){0,80}?</a>', h, re.S | re.I)
        print(f"\n{u}")
        print(f"   jumlah tombol: {len(tombol)}")
        for t in tombol[:2]:
            href = re.search(r'href="([^"]+)"', t)
            warna = re.search(r"background-color:\s*([^;\"]+)", t)
            teks = re.sub(r"<[^>]+>", "", t).strip()
            print(f"   teks: «{teks[:40]}»")
            print(f"   warna: {warna.group(1) if warna else '(dari kelas/teks tema)'}")
            print(f"   tautan: {(href.group(1) if href else '-')[:90]}")
    except Exception as e:
        print(f"\n{u}\n   GAGAL: {str(e)[:60]}")
