Files
Agente-Marketing/casa-hunter/test_apis2.py
T

61 lines
2.3 KiB
Python

import requests, json, re
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124 Safari/537.36",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.9",
"Referer": "https://www.redfin.com/",
}
# Test the correct Redfin GIS endpoint that was working before
print("=== Redfin GIS with region_id ===")
try:
r = requests.get(
"https://www.redfin.com/stingray/api/gis?al=1&market=florida"
"&region_id=14146&region_type=6&status=9&uipt=1,2,3,4"
"&max_price=230000&num_homes=5&start=0&v=8",
headers=headers, timeout=15
)
print(f"Status: {r.status_code}")
raw = r.text.replace("{}&&", "")
data = json.loads(raw)
homes = data.get("payload", {}).get("homes", [])
print(f"Homes: {len(homes)}")
for h in homes[:3]:
print(f" ${h.get('price',{}).get('value',0):,} | {h.get('streetLine',{}).get('value','?')}, {h.get('city','?')} {h.get('zip','')}")
except Exception as e:
print(f"ERROR: {e}")
# Try finding region IDs for our cities
print("\n=== Finding region IDs ===")
cities = ["Vero Beach", "Melbourne", "Jacksonville", "Stuart", "Daytona Beach"]
for city in cities:
try:
r = requests.get(
f"https://www.redfin.com/stingray/do/location-autocomplete?location={requests.utils.quote(city + ' FL')}&count=3&v=2",
headers=headers, timeout=10
)
print(f" {city}: status={r.status_code}, len={len(r.text)}")
raw = r.text.replace("{}&&", "")
if raw.strip():
data = json.loads(raw)
rows = data.get("payload", {}).get("sections", [{}])[0].get("rows", [])
for row in rows[:2]:
print(f" -> id={row.get('id')}, type={row.get('type')}, name={row.get('name')}")
except Exception as e:
print(f" {city}: ERROR {e}")
# Try Redfin search API directly
print("\n=== Redfin /stingray/api/gis-search ===")
try:
r = requests.get(
"https://www.redfin.com/stingray/api/gis-search?"
"al=1&market=florida&region_id=19073&region_type=6"
"&status=9&uipt=1,2,3,4&max_price=230000&num_homes=10&start=0&v=8",
headers=headers, timeout=15
)
print(f"Status: {r.status_code}, size: {len(r.text)}")
print(r.text[:400])
except Exception as e:
print(f"ERROR: {e}")