Skip to content

Commit

Permalink
- redfin init
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyHampton committed Sep 15, 2023
1 parent a79c4c6 commit 469b703
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 4 additions & 2 deletions homeharvest/core/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ def __init__(self, scraper_input: ScraperInput):
"https": scraper_input.proxy_url,
}

def search(self) -> list[Home]:
...
def search(self) -> list[Home]: ...

@staticmethod
def parse_home(home) -> Home: ...
30 changes: 30 additions & 0 deletions homeharvest/core/scrapers/redfin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import json
from ..types import Home, Address
from .. import Scraper


class RedfinScraper(Scraper):
def __init__(self, scraper_input):
super().__init__(scraper_input)

def handle_location(self):
url = 'https://www.redfin.com/stingray/do/location-autocomplete?v=2&al=1&location={}'.format(self.location)

response = self.session.get(url)
response_json = json.loads(response.text.replace('{}&&', ''))

if response_json['payload']['exactMatch'] is not None:
return response_json['payload']['exactMatch']['id'].split('_')[1]
else:
return response_json['payload']['sections'][0]['rows'][0].split('_')[1]

@staticmethod
def parse_home(home) -> Home:
...

def search(self):
region_id = self.handle_location()

url = 'https://www.redfin.com/stingray/api/gis?al=1&region_id={}&region_type=2'.format(region_id)

response = self.session.get(url)
response_json = json.loads(response.text.replace('{}&&', ''))

homes = [self.parse_home(home) for home in response_json['payload']['homes']]
return homes


2 changes: 1 addition & 1 deletion tests/test_redfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def test_redfin():
result = scrape_property(
location="85001"
location="85281"
)

assert result is not None

0 comments on commit 469b703

Please sign in to comment.