import cloudscraper
import time
import random
import string

def random_session():
    return ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))

# Proxy-seller with Indonesian targeting
PROXY_BASE = "http://b04dd480860a80d0-country-id-session-{}:VJvorQIeLmBSK1G9@res.proxy-seller.com:10000"

scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'chrome',
        'platform': 'android',
        'mobile': True
    }
)

for i in range(5):
    session_id = random_session()
    proxy = PROXY_BASE.format(session_id)
    
    print(f"\n[*] Attempt {i+1} with session {session_id}...")
    
    proxies = {
        'http': proxy,
        'https': proxy
    }
    
    try:
        # First check what IP we get
        ip_response = scraper.get('https://api.ipify.org?format=json', proxies=proxies, timeout=30)
        print(f"[*] Proxy IP: {ip_response.json().get('ip', 'unknown')}")
        
        # Now try the target
        response = scraper.get('https://an.fisip.unisri.ac.id/', proxies=proxies, timeout=60)
        print(f"[*] Status: {response.status_code}")
        
        if response.status_code != 403 and 'WordPress' in response.text:
            print("[+] SUCCESS!")
            with open('/tmp/indo_success.html', 'w') as f:
                f.write(response.text)
            break
        elif 'Cloudflare' not in response.text:
            print(f"[?] Different response! Length: {len(response.text)}")
            print(response.text[:300])
            
    except Exception as e:
        print(f"[-] Error: {e}")
    
    time.sleep(2)
