-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a79c4c6
commit 469b703
Showing
3 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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®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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
def test_redfin(): | ||
result = scrape_property( | ||
location="85001" | ||
location="85281" | ||
) | ||
|
||
assert result is not None |