Skip to content

Commit

Permalink
fix: keyerror
Browse files Browse the repository at this point in the history
  • Loading branch information
cullenwatson committed Sep 21, 2023
1 parent f58a1f4 commit 48c2338
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions homeharvest/core/scrapers/redfin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ def search(self):
url = f"https://www.redfin.com/stingray/api/gis?al=1&region_id={region_id}&region_type={region_type}&sold_within_days=30&num_homes=100000"
response = self.session.get(url)
response_json = json.loads(response.text.replace("{}&&", ""))
homes = [self._parse_home(home) for home in response_json["payload"]["homes"]] + [
self._parse_building(building) for building in response_json["payload"]["buildings"].values()
]
return homes

if "payload" in response_json:
homes_list = response_json["payload"].get("homes", [])
buildings_list = response_json["payload"].get("buildings", {}).values()

homes = [self._parse_home(home) for home in homes_list] + [
self._parse_building(building) for building in buildings_list
]
return homes
else:
return []

0 comments on commit 48c2338

Please sign in to comment.