mirror of
https://github.com/Bunsly/HomeHarvest.git
synced 2026-03-04 19:44:29 -08:00
- redfin init
This commit is contained in:
@@ -21,5 +21,7 @@ class Scraper:
|
||||
"https": scraper_input.proxy_url,
|
||||
}
|
||||
|
||||
def search(self) -> list[Home]:
|
||||
...
|
||||
def search(self) -> list[Home]: ...
|
||||
|
||||
@staticmethod
|
||||
def parse_home(home) -> Home: ...
|
||||
|
||||
@@ -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®ion_id={}®ion_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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user