#!/usr/bin/env python3 """ Test Namecheap GraphQL API to find the query hash. """ import asyncio import httpx import json import re async def test_namecheap(): """ Test Namecheap GraphQL API. The API requires a query hash that must be extracted from the website. """ async with httpx.AsyncClient(timeout=30.0) as client: # First, load the Marketplace page to find the hash print("šŸ” Fetching Namecheap Marketplace page...") response = await client.get( "https://www.namecheap.com/market/", headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36", "Accept": "text/html,application/xhtml+xml", } ) if response.status_code == 200: html = response.text # Look for query hash patterns hash_patterns = [ r'"queryHash":"([a-f0-9]+)"', r'"hash":"([a-f0-9]{32,})"', r'aftermarketapi.*?([a-f0-9]{32,})', r'"persistedQueryHash":"([a-f0-9]+)"', ] found_hashes = set() for pattern in hash_patterns: matches = re.findall(pattern, html, re.IGNORECASE) for m in matches: if len(m) >= 32: found_hashes.add(m) if found_hashes: print(f"āœ… Found {len(found_hashes)} potential hashes:") for h in list(found_hashes)[:5]: print(f" {h[:50]}...") else: print("āŒ No hashes found in HTML") # Check for NEXT_DATA if "__NEXT_DATA__" in html: print("šŸ“¦ Found __NEXT_DATA__ - Next.js app") match = re.search(r'', html, re.DOTALL) if match: try: data = json.loads(match.group(1)) print(f" Keys: {list(data.keys())[:5]}") except: pass print(f"šŸ“„ Page status: {response.status_code}") print(f"šŸ“„ Page size: {len(html)} bytes") # Try a different approach - use their search API print("\nšŸ” Trying Namecheap search endpoint...") search_response = await client.get( "https://www.namecheap.com/market/search/", params={"q": "tech"}, headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36", "Accept": "application/json, text/html", "X-Requested-With": "XMLHttpRequest", } ) print(f" Search status: {search_response.status_code}") else: print(f"āŒ Failed: {response.status_code}") if __name__ == "__main__": asyncio.run(test_namecheap())