mirror of
https://github.com/Bunsly/HomeHarvest.git
synced 2026-03-04 19:44:29 -08:00
Fix 403 error from Realtor.com API changes
- Update GraphQL endpoint to api.frontdoor.realtor.com - Update HTTP headers with newer Chrome version and correct client name/version - Improve error handling in handle_home method - Fix response validation for missing/null data 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -81,21 +81,21 @@ class Scraper:
|
|||||||
Scraper.session.mount("https://", adapter)
|
Scraper.session.mount("https://", adapter)
|
||||||
Scraper.session.headers.update(
|
Scraper.session.headers.update(
|
||||||
{
|
{
|
||||||
"accept": "application/json, text/javascript",
|
'sec-ch-ua-platform': '"macOS"',
|
||||||
"accept-language": "en-US,en;q=0.9",
|
'rdc-client-name': 'rdc-search-for-sale-desktop',
|
||||||
"cache-control": "no-cache",
|
'sec-ch-ua': '"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"',
|
||||||
"content-type": "application/json",
|
'sec-ch-ua-mobile': '?0',
|
||||||
"origin": "https://www.realtor.com",
|
'rdc-client-version': '0.1.0',
|
||||||
"pragma": "no-cache",
|
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
|
||||||
"priority": "u=1, i",
|
'accept': 'application/json',
|
||||||
"rdc-ab-tests": "commute_travel_time_variation:v1",
|
'content-type': 'application/json',
|
||||||
"sec-ch-ua": '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
|
'origin': 'https://www.realtor.com',
|
||||||
"sec-ch-ua-mobile": "?0",
|
'sec-fetch-site': 'same-site',
|
||||||
"sec-ch-ua-platform": '"Windows"',
|
'sec-fetch-mode': 'cors',
|
||||||
"sec-fetch-dest": "empty",
|
'sec-fetch-dest': 'empty',
|
||||||
"sec-fetch-mode": "cors",
|
'referer': 'https://www.realtor.com/',
|
||||||
"sec-fetch-site": "same-origin",
|
'accept-language': 'en-US,en;q=0.9',
|
||||||
"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",
|
'priority': 'u=1, i',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,7 @@ from .processors import (
|
|||||||
|
|
||||||
|
|
||||||
class RealtorScraper(Scraper):
|
class RealtorScraper(Scraper):
|
||||||
SEARCH_GQL_URL = "https://www.realtor.com/api/v1/rdc_search_srp?client_id=rdc-search-new-communities&schema=vesta"
|
SEARCH_GQL_URL = "https://api.frontdoor.realtor.com/graphql"
|
||||||
PROPERTY_URL = "https://www.realtor.com/realestateandhomes-detail/"
|
|
||||||
PROPERTY_GQL = "https://graph.realtor.com/graphql"
|
|
||||||
ADDRESS_AUTOCOMPLETE_URL = "https://parser-external.geo.moveaws.com/suggest"
|
ADDRESS_AUTOCOMPLETE_URL = "https://parser-external.geo.moveaws.com/suggest"
|
||||||
NUM_PROPERTY_WORKERS = 20
|
NUM_PROPERTY_WORKERS = 20
|
||||||
DEFAULT_PAGE_SIZE = 200
|
DEFAULT_PAGE_SIZE = 200
|
||||||
@@ -108,6 +106,7 @@ class RealtorScraper(Scraper):
|
|||||||
return property_info["listings"][0]["listing_id"]
|
return property_info["listings"][0]["listing_id"]
|
||||||
|
|
||||||
def handle_home(self, property_id: str) -> list[Property]:
|
def handle_home(self, property_id: str) -> list[Property]:
|
||||||
|
"""Fetch single home with proper error handling."""
|
||||||
query = (
|
query = (
|
||||||
"""query Home($property_id: ID!) {
|
"""query Home($property_id: ID!) {
|
||||||
home(property_id: $property_id) %s
|
home(property_id: $property_id) %s
|
||||||
@@ -116,23 +115,33 @@ class RealtorScraper(Scraper):
|
|||||||
)
|
)
|
||||||
|
|
||||||
variables = {"property_id": property_id}
|
variables = {"property_id": property_id}
|
||||||
payload = {
|
payload = {"query": query, "variables": variables}
|
||||||
"query": query,
|
|
||||||
"variables": variables,
|
|
||||||
}
|
|
||||||
|
|
||||||
response = self.session.post(self.SEARCH_GQL_URL, json=payload)
|
try:
|
||||||
response_json = response.json()
|
response = self.session.post(self.SEARCH_GQL_URL, json=payload)
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
property_info = response_json["data"]["home"]
|
# Check for errors or missing data
|
||||||
|
if "errors" in data or "data" not in data:
|
||||||
|
return []
|
||||||
|
|
||||||
if self.return_type != ReturnType.raw:
|
if data["data"] is None or "home" not in data["data"]:
|
||||||
return [process_property(property_info, self.mls_only, self.extra_property_data,
|
return []
|
||||||
self.exclude_pending, self.listing_type, get_key, process_extra_property_details)]
|
|
||||||
else:
|
|
||||||
return [property_info]
|
|
||||||
|
|
||||||
|
property_info = data["data"]["home"]
|
||||||
|
if property_info is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Process based on return type
|
||||||
|
if self.return_type != ReturnType.raw:
|
||||||
|
return [process_property(property_info, self.mls_only, self.extra_property_data,
|
||||||
|
self.exclude_pending, self.listing_type, get_key,
|
||||||
|
process_extra_property_details)]
|
||||||
|
else:
|
||||||
|
return [property_info]
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
|
|
||||||
def general_search(self, variables: dict, search_type: str) -> Dict[str, Union[int, Union[list[Property], list[dict]]]]:
|
def general_search(self, variables: dict, search_type: str) -> Dict[str, Union[int, Union[list[Property], list[dict]]]]:
|
||||||
"""
|
"""
|
||||||
@@ -366,7 +375,7 @@ class RealtorScraper(Scraper):
|
|||||||
$city: String,
|
$city: String,
|
||||||
$county: [String],
|
$county: [String],
|
||||||
$state_code: String,
|
$state_code: String,
|
||||||
$postal_code: String
|
$postal_code: String,
|
||||||
$offset: Int,
|
$offset: Int,
|
||||||
) {
|
) {
|
||||||
home_search(
|
home_search(
|
||||||
|
|||||||
Reference in New Issue
Block a user