Spaces:
Paused
Paused
Update scraper.py
Browse files- scraper.py +0 -7
scraper.py
CHANGED
|
@@ -7,7 +7,6 @@ from curl_cffi.requests import AsyncSession
|
|
| 7 |
async def check_fragment(word: str, proxy_url: str = None) -> str:
|
| 8 |
url = f"https://fragment.com/username/{word}"
|
| 9 |
|
| 10 |
-
# Format proxy for curl_cffi (Applies to both HTTP and HTTPS traffic)
|
| 11 |
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
|
| 12 |
|
| 13 |
async with AsyncSession(impersonate="chrome120", proxies=proxies) as session:
|
|
@@ -21,17 +20,14 @@ async def check_fragment(word: str, proxy_url: str = None) -> str:
|
|
| 21 |
|
| 22 |
html = resp.text
|
| 23 |
|
| 24 |
-
# Cloudflare challenge - rotate proxy or wait
|
| 25 |
if "Just a moment..." in html or "cloudflare" in html.lower():
|
| 26 |
await asyncio.sleep(random.uniform(2, 4))
|
| 27 |
continue
|
| 28 |
|
| 29 |
-
# 1. Canonical Rule: If redirected to homepage, username is soft-banned/Unavailable
|
| 30 |
canonical = re.search(r'<link rel="canonical" href="([^"]+)"', html, re.IGNORECASE)
|
| 31 |
if canonical and "/username/" not in canonical.group(1):
|
| 32 |
return "UNAVAILABLE"
|
| 33 |
|
| 34 |
-
# 2. Extract specific status text
|
| 35 |
status_match = re.search(r'class="tm-section-header-status[^"]*"[^>]*>\s*([^<]+?)\s*</span>', html, re.IGNORECASE)
|
| 36 |
|
| 37 |
if status_match:
|
|
@@ -42,16 +38,13 @@ async def check_fragment(word: str, proxy_url: str = None) -> str:
|
|
| 42 |
if "available" in s: return "AVAILABLE"
|
| 43 |
if "sale" in s or "purchase" in s: return "FOR_SALE"
|
| 44 |
|
| 45 |
-
# Async I/O for unknown statuses
|
| 46 |
clean = s.upper()
|
| 47 |
async with aiofiles.open("other.txt", "a", encoding="utf-8") as f:
|
| 48 |
await f.write(f"{word} - {clean} (Proxy: {proxy_url})\n")
|
| 49 |
return clean
|
| 50 |
|
| 51 |
-
# 3. Fallbacks
|
| 52 |
if "tm-status-taken" in html: return "TAKEN"
|
| 53 |
if "tm-status-unavail" in html:
|
| 54 |
-
# Prevent false Unavailable markings for Sold pages
|
| 55 |
if ">Sold<" in html or ">sold<" in html.lower():
|
| 56 |
return "SOLD"
|
| 57 |
return "UNAVAILABLE"
|
|
|
|
| 7 |
async def check_fragment(word: str, proxy_url: str = None) -> str:
|
| 8 |
url = f"https://fragment.com/username/{word}"
|
| 9 |
|
|
|
|
| 10 |
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
|
| 11 |
|
| 12 |
async with AsyncSession(impersonate="chrome120", proxies=proxies) as session:
|
|
|
|
| 20 |
|
| 21 |
html = resp.text
|
| 22 |
|
|
|
|
| 23 |
if "Just a moment..." in html or "cloudflare" in html.lower():
|
| 24 |
await asyncio.sleep(random.uniform(2, 4))
|
| 25 |
continue
|
| 26 |
|
|
|
|
| 27 |
canonical = re.search(r'<link rel="canonical" href="([^"]+)"', html, re.IGNORECASE)
|
| 28 |
if canonical and "/username/" not in canonical.group(1):
|
| 29 |
return "UNAVAILABLE"
|
| 30 |
|
|
|
|
| 31 |
status_match = re.search(r'class="tm-section-header-status[^"]*"[^>]*>\s*([^<]+?)\s*</span>', html, re.IGNORECASE)
|
| 32 |
|
| 33 |
if status_match:
|
|
|
|
| 38 |
if "available" in s: return "AVAILABLE"
|
| 39 |
if "sale" in s or "purchase" in s: return "FOR_SALE"
|
| 40 |
|
|
|
|
| 41 |
clean = s.upper()
|
| 42 |
async with aiofiles.open("other.txt", "a", encoding="utf-8") as f:
|
| 43 |
await f.write(f"{word} - {clean} (Proxy: {proxy_url})\n")
|
| 44 |
return clean
|
| 45 |
|
|
|
|
| 46 |
if "tm-status-taken" in html: return "TAKEN"
|
| 47 |
if "tm-status-unavail" in html:
|
|
|
|
| 48 |
if ">Sold<" in html or ">sold<" in html.lower():
|
| 49 |
return "SOLD"
|
| 50 |
return "UNAVAILABLE"
|