#!/usr/bin/env python3
"""Coba beberapa cara mengambil berkas gambar TSC (uji apakah Cloudflare memblokir permintaan gambar)."""
import time, urllib.error, urllib.request

URL = "https://www.theskincodeclinic.com/wp-content/uploads/2026/09/featured-dokter-kulit-sidoarjo.png"
COBA = [
    ("UA bot biasa", {"User-Agent": "Mozilla/5.0"}),
    ("UA Chrome lengkap", {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
                                        "(KHTML, like Gecko) Chrome/124.0 Safari/537.36",
                           "Accept": "image/avif,image/webp,image/png,image/*,*/*;q=0.8",
                           "Accept-Language": "id-ID,id;q=0.9,en;q=0.8",
                           "Referer": "https://www.theskincodeclinic.com/"}),
    ("UA Googlebot", {"User-Agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}),
    ("tanpa UA", {}),
]
for label, kepala in COBA:
    try:
        with urllib.request.urlopen(urllib.request.Request(URL, headers=kepala), timeout=45) as x:
            isi = x.read()
            print(f"  {label:<18} HTTP {x.status} · {len(isi) // 1024} KB · tipe {x.headers.get('content-type')}")
            break
    except urllib.error.HTTPError as e:
        print(f"  {label:<18} HTTP {e.code} · {e.headers.get('cf-mitigated', '-')}")
    except Exception as e:
        print(f"  {label:<18} {str(e)[:50]}")
    time.sleep(2)

print("\nuji berkas gambar lain yang pasti ada (dari artikel yang tayang):")
URL2 = "https://www.theskincodeclinic.com/wp-content/uploads/2026/06/skin-code-clinic.jpg"
try:
    with urllib.request.urlopen(urllib.request.Request(URL2, headers={"User-Agent": "Mozilla/5.0"}), timeout=45) as x:
        print(f"  HTTP {x.status} · {len(x.read()) // 1024} KB")
except urllib.error.HTTPError as e:
    print(f"  HTTP {e.code}")
