mirror of
https://github.com/Bunsly/HomeHarvest.git
synced 2026-03-04 19:44:29 -08:00
enh: property type (#102)
This commit is contained in:
@@ -5,7 +5,7 @@ from requests.adapters import HTTPAdapter
|
||||
from urllib3.util.retry import Retry
|
||||
import uuid
|
||||
from ...exceptions import AuthenticationError
|
||||
from .models import Property, ListingType, SiteName
|
||||
from .models import Property, ListingType, SiteName, SearchPropertyType
|
||||
import json
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import json
|
||||
class ScraperInput:
|
||||
location: str
|
||||
listing_type: ListingType
|
||||
property_type: list[SearchPropertyType] | None = None
|
||||
radius: float | None = None
|
||||
mls_only: bool | None = False
|
||||
proxy: str | None = None
|
||||
@@ -34,11 +35,12 @@ class Scraper:
|
||||
):
|
||||
self.location = scraper_input.location
|
||||
self.listing_type = scraper_input.listing_type
|
||||
self.property_type = scraper_input.property_type
|
||||
|
||||
if not self.session:
|
||||
Scraper.session = requests.Session()
|
||||
retries = Retry(
|
||||
total=3, backoff_factor=3, status_forcelist=[429, 403], allowed_methods=frozenset(["GET", "POST"])
|
||||
total=3, backoff_factor=4, status_forcelist=[429, 403], allowed_methods=frozenset(["GET", "POST"])
|
||||
)
|
||||
|
||||
adapter = HTTPAdapter(max_retries=retries)
|
||||
@@ -46,21 +48,21 @@ class Scraper:
|
||||
Scraper.session.mount("https://", adapter)
|
||||
Scraper.session.headers.update(
|
||||
{
|
||||
'accept': 'application/json, text/javascript',
|
||||
'accept-language': 'en-US,en;q=0.9',
|
||||
'cache-control': 'no-cache',
|
||||
'content-type': 'application/json',
|
||||
'origin': 'https://www.realtor.com',
|
||||
'pragma': 'no-cache',
|
||||
'priority': 'u=1, i',
|
||||
'rdc-ab-tests': 'commute_travel_time_variation:v1',
|
||||
'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
|
||||
"accept": "application/json, text/javascript",
|
||||
"accept-language": "en-US,en;q=0.9",
|
||||
"cache-control": "no-cache",
|
||||
"content-type": "application/json",
|
||||
"origin": "https://www.realtor.com",
|
||||
"pragma": "no-cache",
|
||||
"priority": "u=1, i",
|
||||
"rdc-ab-tests": "commute_travel_time_variation:v1",
|
||||
"sec-ch-ua": '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
|
||||
"sec-ch-ua-mobile": "?0",
|
||||
"sec-ch-ua-platform": '"Windows"',
|
||||
"sec-fetch-dest": "empty",
|
||||
"sec-fetch-mode": "cors",
|
||||
"sec-fetch-site": "same-origin",
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -94,27 +96,29 @@ class Scraper:
|
||||
response = requests.post(
|
||||
"https://graph.realtor.com/auth/token",
|
||||
headers={
|
||||
'Host': 'graph.realtor.com',
|
||||
'Accept': '*/*',
|
||||
'Content-Type': 'Application/json',
|
||||
'X-Client-ID': 'rdc_mobile_native,iphone',
|
||||
'X-Visitor-ID': device_id,
|
||||
'X-Client-Version': '24.21.23.679885',
|
||||
'Accept-Language': 'en-US,en;q=0.9',
|
||||
'User-Agent': 'Realtor.com/24.21.23.679885 CFNetwork/1494.0.7 Darwin/23.4.0',
|
||||
"Host": "graph.realtor.com",
|
||||
"Accept": "*/*",
|
||||
"Content-Type": "Application/json",
|
||||
"X-Client-ID": "rdc_mobile_native,iphone",
|
||||
"X-Visitor-ID": device_id,
|
||||
"X-Client-Version": "24.21.23.679885",
|
||||
"Accept-Language": "en-US,en;q=0.9",
|
||||
"User-Agent": "Realtor.com/24.21.23.679885 CFNetwork/1494.0.7 Darwin/23.4.0",
|
||||
},
|
||||
data=json.dumps({
|
||||
"grant_type": "device_mobile",
|
||||
"device_id": device_id,
|
||||
"client_app_id": "rdc_mobile_native,24.21.23.679885,iphone"
|
||||
}))
|
||||
data=json.dumps(
|
||||
{
|
||||
"grant_type": "device_mobile",
|
||||
"device_id": device_id,
|
||||
"client_app_id": "rdc_mobile_native,24.21.23.679885,iphone",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
data = response.json()
|
||||
|
||||
if not (access_token := data.get("access_token")):
|
||||
raise AuthenticationError(
|
||||
"Failed to get access token, use a proxy/vpn or wait a moment and try again.",
|
||||
response=response
|
||||
"Failed to get access token, use a proxy/vpn or wait a moment and try again.", response=response
|
||||
)
|
||||
|
||||
return access_token
|
||||
|
||||
Reference in New Issue
Block a user