Files

60 lines
2.3 KiB
Python

import requests, json, sys
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",
}
# 1. Redfin city lookup
print("=== Redfin City IDs ===")
for city in ["Vero Beach, FL", "Jacksonville, FL", "Melbourne, FL", "Stuart, FL", "St. Augustine, FL"]:
try:
r = requests.get(
f"https://www.redfin.com/stingray/do/location-autocomplete?location={requests.utils.quote(city)}&count=3&v=2",
headers=headers, timeout=10
)
data = json.loads(r.text.replace("{}&&", ""))
rows = data.get("payload", {}).get("sections", [{}])[0].get("rows", [])
if rows:
row = rows[0]
print(f" {city}: id={row.get('id')}, type={row.get('type')}, url={row.get('url','')}")
else:
print(f" {city}: no result")
except Exception as e:
print(f" {city}: ERROR {e}")
# 2. Test Redfin search with a known city
print("\n=== Redfin Search Sample (Vero Beach, FL) ===")
try:
# region_id for Vero Beach found via autocomplete
r = requests.get(
"https://www.redfin.com/stingray/api/gis?al=1&market=florida"
"&region_type=6&status=9&uipt=1,2,3,4&max_price=230000&num_homes=5&start=0&v=8"
"&location=Vero+Beach%2C+FL",
headers=headers, timeout=15
)
data = json.loads(r.text.replace("{}&&", ""))
homes = data.get("payload", {}).get("homes", [])
print(f" Found: {len(homes)} homes")
for h in homes[:3]:
print(f" - ${h.get('price',{}).get('value','?'):,} | {h.get('streetLine',{}).get('value','?')}, {h.get('city','?')}")
except Exception as e:
print(f" ERROR: {e}")
# 3. Test Redfin with city URL slug
print("\n=== Redfin via city page ===")
try:
r = requests.get(
"https://www.redfin.com/city/19073/FL/Vero-Beach/filter/max-price=230000,property-type=house+condo+townhouse",
headers=headers, timeout=15
)
import re
match = re.search(r'"payload":\s*\{.*?"homes":\s*(\[.*?\])\s*,\s*"(?:totalRowCount|url)"', r.text, re.DOTALL)
if match:
homes = json.loads(match.group(1))
print(f" Found {len(homes)} homes via page")
else:
print(f" Status {r.status_code}, size {len(r.text)} - no match")
except Exception as e:
print(f" ERROR: {e}")