Skip to content

Commit

Permalink
- zillow location validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyHampton committed Sep 19, 2023
1 parent 087854a commit 78b56c2
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions homeharvest/core/scrapers/zillow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@
class ZillowScraper(Scraper):
def __init__(self, scraper_input):
super().__init__(scraper_input)
self.listing_type = scraper_input.listing_type

if not self.is_plausible_location(self.location):
raise NoResultsFound("Invalid location input: {}".format(self.location))

if self.listing_type == ListingType.FOR_SALE:
self.url = f"https://www.zillow.com/homes/for_sale/{self.location}_rb/"
elif self.listing_type == ListingType.FOR_RENT:
self.url = f"https://www.zillow.com/homes/for_rent/{self.location}_rb/"
else:
self.url = f"https://www.zillow.com/homes/recently_sold/{self.location}_rb/"

@staticmethod
def is_plausible_location(location: str) -> bool:
blocks = location.split()
for block in blocks:
if (
any(char.isdigit() for char in block)
and any(char.isalpha() for char in block)
and len(block) > 6
):
return False
return True
def is_plausible_location(self, location: str) -> bool:
url = ('https://www.zillowstatic.com/autocomplete/v3/suggestions?q={'
'}&abKey=6666272a-4b99-474c-b857-110ec438732b&clientId=homepage-render').format(
location
)

response = self.session.get(url)

return response.json()['results'] != []

def search(self):
resp = self.session.get(self.url, headers=self._get_headers())
Expand Down

0 comments on commit 78b56c2

Please sign in to comment.