mirror of
https://github.com/Bunsly/HomeHarvest.git
synced 2026-03-11 07:54:31 -07:00
fix(zillow): test case
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import re
|
||||
import json
|
||||
import string
|
||||
from .. import Scraper
|
||||
from ....utils import parse_address_two, parse_unit
|
||||
from ....exceptions import GeoCoordsNotFound, NoResultsFound
|
||||
from ..models import Property, Address, ListingType, PropertyType, SiteName
|
||||
from ..models import Property, Address, ListingType, PropertyType
|
||||
|
||||
|
||||
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:
|
||||
@@ -17,6 +20,18 @@ class ZillowScraper(Scraper):
|
||||
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 search(self):
|
||||
resp = self.session.get(self.url, headers=self._get_headers())
|
||||
resp.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user