Files

59 lines
2.4 KiB
Python

import requests, re, json
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9",
}
# Fetch Redfin search for FL cities and extract real region IDs
test_urls = [
("Vero Beach", "https://www.redfin.com/FL/Vero-Beach"),
("Jacksonville", "https://www.redfin.com/FL/Jacksonville"),
("Melbourne", "https://www.redfin.com/FL/Melbourne"),
("Stuart", "https://www.redfin.com/FL/Stuart"),
("Daytona Beach", "https://www.redfin.com/FL/Daytona-Beach"),
]
print("=== Extracting real Redfin region IDs ===")
for city, url in test_urls:
try:
r = requests.get(url, headers=headers, timeout=15, allow_redirects=True)
# Extract region_id from JS or URL
final_url = r.url
match = re.search(r'/city/(\d+)/FL/', final_url)
if not match:
match = re.search(r'"region_id"[:\s]+(\d+)', r.text)
if not match:
match = re.search(r'"regionId"[:\s]+(\d+)', r.text)
if match:
rid = match.group(1)
print(f" {city}: region_id={rid} (url={final_url})")
else:
print(f" {city}: redirected to {final_url}, id not found, status={r.status_code}")
except Exception as e:
print(f" {city}: ERROR {e}")
# Try direct Redfin search API (county-based = more reliable)
print("\n=== Redfin by ZIP code (more reliable) ===")
fl_zips = {
"Vero Beach": "32960",
"Melbourne": "32901",
"Jacksonville": "32202",
"St. Augustine": "32080",
"Daytona Beach": "32114",
}
for city, zipcode in fl_zips.items():
try:
url = (f"https://www.redfin.com/stingray/api/gis?"
f"al=1&market=florida&region_id={zipcode}&region_type=2"
f"&status=9&uipt=1,2,3,4&max_price=230000&num_homes=5&start=0&v=8")
r = requests.get(url, headers=headers, timeout=15)
data = json.loads(r.text.replace("{}&&", ""))
homes = data.get("payload", {}).get("homes", [])
fl_homes = [h for h in homes if h.get("state") == "FL"]
print(f" {city} (zip={zipcode}): {len(homes)} total, {len(fl_homes)} in FL")
for h in fl_homes[:2]:
print(f" ${h.get('price',{}).get('value',0):,} | {h.get('streetLine',{}).get('value','?')}, {h.get('city','?')}, FL")
except Exception as e:
print(f" {city}: ERROR {e}")