Wasifali95's picture
Upload 3 files
9f2aabb verified
Raw
History Blame Contribute Delete
4.62 kB
import cloudscraper
from bs4 import BeautifulSoup
from fastapi import FastAPI, Query
from fastapi.responses import JSONResponse
import time
import json
app = FastAPI()
# Cloudscraper with default settings (Chrome ki zaroorat nahi)
scraper = cloudscraper.create_scraper(
interpreter='nodejs', # Node.js interpreter - lighter than Chrome
delay=15, # Thoda delay Cloudflare ko bypass karne ke liye
browser={
'browser': 'firefox',
'platform': 'windows',
'mobile': False
}
)
# Cookie persistence for session
session_cookies = {}
@app.get("/")
def read_root():
return {
"message": "SIM Database Checker API",
"developer": "WASIF ALI",
"endpoint": "/check?phone=3xxxxxxx",
"status": "active"
}
@app.get("/check")
def check_number(phone: str = Query(..., description="Phone number to check")):
if not phone:
return JSONResponse(
status_code=400,
content={"success": False, "message": "Phone number required"}
)
try:
# Step 1: Main page se session start
print(f"🌐 Visiting main page for {phone}")
main_response = scraper.get(
"https://freshsimdatabases.com/",
timeout=30,
allow_redirects=True
)
# Step 2: Search page par POST
print(f"📤 Submitting number {phone}")
response = scraper.post(
"https://freshsimdatabases.com/number_dattta.php",
data=f"numberCnic={phone}&searchNumber=",
headers={
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://freshsimdatabases.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive"
},
timeout=45
)
# Check if blocked
if response.status_code == 403 or "cf-challenge" in response.text.lower():
return {
"success": False,
"message": "Cloudflare blocking detected. The site has bot protection.",
"suggestion": "Try using a VPN or proxy",
"developer": "WASIF ALI"
}
# Parse HTML
soup = BeautifulSoup(response.text, 'html.parser')
records = []
# Try different table selectors
tables = soup.find_all('table')
for table in tables:
rows = table.find_all('tr')
for row in rows:
cols = row.find_all('td')
if len(cols) >= 4:
mobile = cols[0].get_text(strip=True)
if mobile and len(mobile) >= 10: # Valid phone number
records.append({
"Mobile": mobile,
"Name": cols[1].get_text(strip=True) if len(cols) > 1 else "",
"CNIC": cols[2].get_text(strip=True) if len(cols) > 2 else "",
"Address": cols[3].get_text(strip=True) if len(cols) > 3 else ""
})
if records:
return {
"success": True,
"count": len(records),
"records": records,
"developer": "WASIF ALI",
"telegram": "@FREEHACKS95"
}
else:
# No records found
return {
"success": False,
"message": "No records found for this number",
"developer": "WASIF ALI"
}
except cloudscraper.exceptions.CloudflareChallengeError as e:
return JSONResponse(
status_code=503,
content={
"success": False,
"error": "Cloudflare challenge detected",
"message": "Site has bot protection. This API cannot bypass it.",
"developer": "WASIF ALI"
}
)
except Exception as e:
return JSONResponse(
status_code=500,
content={
"success": False,
"error": str(e),
"message": "Server error occurred",
"developer": "WASIF ALI"
}
)
# Health check endpoint
@app.get("/health")
def health_check():
return {"status": "running"}