Skip to content

Commit

Permalink
- optimizations & updated realtor headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyHampton committed May 20, 2024
1 parent aacd168 commit ec036bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 1 addition & 3 deletions homeharvest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ def scrape_property(
site = RealtorScraper(scraper_input)
results = site.search()

properties_dfs = [process_result(result) for result in results]
properties_dfs = [df for result in results if not (df := process_result(result)).empty]
if not properties_dfs:
return pd.DataFrame()

properties_dfs = [df for df in properties_dfs if not df.empty]

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)

Expand Down
32 changes: 20 additions & 12 deletions homeharvest/core/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid
from ...exceptions import AuthenticationError
from .models import Property, ListingType, SiteName
import json


@dataclass
Expand Down Expand Up @@ -71,18 +72,25 @@ def handle_location(self): ...

@staticmethod
def get_access_token():
url = "https://graph.realtor.com/auth/token"

payload = f'{{"client_app_id":"rdc_mobile_native,24.20.4.149916,iphone","device_id":"{str(uuid.uuid4()).upper()}","grant_type":"device_mobile"}}'
headers = {
"Host": "graph.realtor.com",
"x-client-version": "24.20.4.149916",
"accept": "*/*",
"content-type": "Application/json",
"user-agent": "Realtor.com/24.20.4.149916 CFNetwork/1410.0.3 Darwin/22.6.0",
"accept-language": "en-US,en;q=0.9",
}
response = requests.post(url, headers=headers, data=payload)
device_id = str(uuid.uuid4()).upper()

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',
},
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()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "homeharvest"
version = "0.3.27"
version = "0.3.28"
description = "Real estate scraping library"
authors = ["Zachary Hampton <[email protected]>", "Cullen Watson <[email protected]>"]
homepage = "https://github.com/Bunsly/HomeHarvest"
Expand Down

0 comments on commit ec036bb

Please sign in to comment.