File size: 2,500 Bytes
6d07192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
import json
import time

API_URL = "https://ubuntu593-alt-scraper-api.hf.space/api/seo-report"

DOMAINS_TO_TEST = [
    {"url": "https://www.example.com", "limit": 1, "desc": "Simple Static Site"},
    {"url": "https://www.google.com", "limit": 1, "desc": "Big Tech (High Robustness)"},
    {"url": "https://www.wikipedia.org", "limit": 2, "desc": "Content Heavy"},
    {"url": "https://www.amazon.in", "limit": 1, "desc": "Anti-Bot Heavy (Amazon)"},
]

def run_tests():
    print(f"Starting Live API Tests against: {API_URL}\n")
    print("-" * 60)
    
    results = []

    for item in DOMAINS_TO_TEST:
        domain = item['url']
        limit = item['limit']
        desc = item['desc']
        
        print(f"Testing: {domain} ({desc})...", end=" ", flush=True)
        
        start_time = time.time()
        try:
            # We use a POST or GET. The API supports both, let's try POST for parameters.
            payload = {"domain": domain, "limit": limit}
            response = requests.post(API_URL, json=payload, timeout=60)
            
            elapsed = time.time() - start_time
            
            if response.status_code == 200:
                data = response.json()
                summary = data.get('summary', {})
                discovered = summary.get('total_pages_discovered', 0)
                images = summary.get('total_images_found', 0)
                
                print(f"SUCCESS ({elapsed:.2f}s)")
                print(f"   -> Pages Scanned: {summary.get('total_pages_scanned')}")
                print(f"   -> Images Found: {images}")
                print(f"   -> Details: {summary}")
                results.append({"domain": domain, "status": "PASS", "time": elapsed, "data": summary})
            else:
                print(f"FAILED ({response.status_code})")
                print(f"   -> Response: {response.text[:200]}")
                results.append({"domain": domain, "status": "FAIL", "code": response.status_code})
                
        except Exception as e:
            print(f"ERROR: {str(e)}")
            results.append({"domain": domain, "status": "ERROR", "error": str(e)})
        
        print("-" * 60)

    # Final Summary
    print("\nTEST SUMMARY")
    print("=" * 60)
    for res in results:
        status_icon = "[PASS]" if res['status'] == "PASS" else "[FAIL]"
        print(f"{status_icon} {res['domain']:<30} | {res['status']}")
    print("=" * 60)

if __name__ == "__main__":
    run_tests()